Visitar URL original
fix: Fix zizmor handling of numbers in expressions by DarkaMaul · Pull Request #1628 · zizmorcore/zizmor · GitHub
Skip to content

fix: Fix zizmor handling of numbers in expressions - #1628

Merged
woodruffw merged 5 commits into
zizmorcore:mainfrom
trail-of-forks:dm/expression-number
Feb 25, 2026
Merged

woodruffw merged 5 commits into
zizmorcore:mainfrom
trail-of-forks:dm/expression-number

Conversation

@DarkaMaul

Copy link
Copy Markdown
Contributor

Pre-submission checks

Please check these boxes:

  • Mandatory: This PR corresponds to an issue (if not, please create
    one first) ( [BUG]: Incorrect evaluation of number in expressions #1625)

  • I hereby disclose the use of an LLM or other AI coding assistant in the
    creation of this PR. PRs will not be rejected for using AI tools, but
    will be rejected for undisclosed use.

If a checkbox is not applicable, you can leave it unchecked.

Summary

The PR fixes zizmor handling of numbers in expression to align it with GitHub Action expression parser.

Test Plan

This change is self contained with multiple tests. The only problem is that we have no easy way of tracking GitHub changes to their expression parser.

Comment on lines +760 to +767
/// Parse a string into a number following GitHub Actions coercion rules.
///
/// The string is trimmed and then parsed as:
/// - Empty/whitespace-only → 0.0
/// - `0x` prefix → hexadecimal integer
/// - `0o` prefix → octal integer
/// - Otherwise → standard float parsing (decimal, scientific notation,
/// Infinity, -Infinity, NaN)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are octals and hex numbers actually supported by GHA? The docs are naturally unclear:

https://docs.github.com/en/enterprise-cloud@latest/actions/reference/workflows-and-actions/expressions#literals

(The docs for number say "any JSON number," which would need to be base 10. But then the example immediately below shows a hex number, naturally.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If so, there's a possibility we need to update the Pest grammar as well.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m on my phone right now but the workflow here shows that it does support octal and hexadecimal : https://github.com/trail-of-forks/zizmor/actions/runs/22103104435/job/63877999605

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. In that case I think we do (unfortunately) need to ensure our grammar handles those, plus implement the full JS coercion/number literal rules.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, what the hell. I don't really understand where GitHub Actions number semantics come from, then. I think we need to fully understand how their own parser/evaluator works here before we can address this.

Would you mind going through that source tree and trying to understand what they're actually doing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it here: https://github.com/actions/runner/blob/main/src/Sdk/Expressions/Sdk/ExpressionUtility.cs#L223

I had an AI extract this function, create a binary, and reproduce the workflow result!

I'm working on aligning our parse_number_from_str on their function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new implementation is aligned with the GH Action Runner one, and it matches the behavior of my test run here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll try and take a look today.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @DarkaMaul! I think the pest grammar itself still needs to be updated too, right now it doesn't allow hex, octal, or exponent forms in the grammar itself.

@woodruffw woodruffw added bugfix Fixes a known bug autofix:unsound labels Feb 17, 2026
@DarkaMaul
DarkaMaul force-pushed the dm/expression-number branch 2 times, most recently from ea773fa to fa67fd7 Compare February 20, 2026 10:53
@DarkaMaul
DarkaMaul force-pushed the dm/expression-number branch from fa67fd7 to b4f0e47 Compare February 20, 2026 10:55
@DarkaMaul
DarkaMaul force-pushed the dm/expression-number branch from 079e983 to 9d59acb Compare February 23, 2026 09:58

@woodruffw woodruffw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DarkaMaul, nice work!

Please add a release-notes entry and this'll be good to go 🙂

(Normally I'd push up on your branch but this is on trail-of-forks, so there's the GitHub org 3P PR bug blocking it.)

@DarkaMaul
DarkaMaul force-pushed the dm/expression-number branch from 585e88f to bb9e328 Compare February 25, 2026 08:39
@woodruffw
woodruffw merged commit b7a5736 into zizmorcore:main Feb 25, 2026
12 checks passed
@DarkaMaul
DarkaMaul deleted the dm/expression-number branch February 25, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autofix:unsound bugfix Fixes a known bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants