Skip to content

fix: reject non-integer expr arithmetic operands - #757

Open
tanav29 wants to merge 4 commits into
vercel-labs:mainfrom
tanav29:fix/expr-integer-operands
Open

tanav29 wants to merge 4 commits into
vercel-labs:mainfrom
tanav29:fix/expr-integer-operands

Conversation

@tanav29

@tanav29 tanav29 commented Nov 11, 2026 •

Copy link
Copy Markdown

Fixes #741.

Require complete integer operands for arithmetic and compare non-integer operands as strings. This prevents decimal and other partially numeric values from being silently truncated.

Validation: focused expr regression tests (7 passed).

@vercel

vercel Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@tanav29 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@auto-maintain

auto-maintain Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🤖 auto-maintain review

Automated, advisory triage for @tanav29's PR. Facts below are read from the GitHub API.

Check Result
Author's merged PRs (this repo) 0 — ⚠️ first-time contributor
Account established ✅ (age 2413d · 41 followers · 142 public repos)
Commits signed/verified ⚠️ 0/4
Changeset included ⚠️

Review panel: 🟡 medium highest severity

just-bash maintainer code review: 🟢 low

No actionable correctness or maintainability issues found in the complete diff.

General code review: 🟡 medium

The stricter parsing works for small operands, but large valid integers remain observably incorrect.

  • packages/just-bash/src/commands/expr/expr.ts:54 — Integer operands are still converted to IEEE-754 numbers, so valid large integers silently lose precision. For example, `expr 9007199254740992 = 9007199254740993` reports equality and adding 1 returns the unchanged value. Use exact integer arithmetic such as BigInt; the new power-of-ten tests miss this boundary.

Adversarial security: 🟢 low

No actionable adversarial security issues found in the complete diff.

Adversarial security (second opinion): 🟡 medium

No security concerns: the change is confined to pure integer-parsing and string-ordering logic in expr with no new I/O, process, dependency, or CI surface; the only actionable issue is that the new code-point comparison routine ships effectively untested.

  • packages/just-bash/src/commands/expr/expr.test.ts:32 — The test case labeled "compares strings by code point" uses ASCII question marks (`expr '1??' '<' '1?'`), which is just a prefix comparison that the previous native `left < right` also answered identically. The new hand-rolled `compareStrings` only diverges from JS string comparison for supplementary-plane code points (e.g. U+10000 vs U+FFFF, where UTF-16 code-unit order and code-point order disagree), so this test gives zero coverage of the one behavior the function was added for. The characters look like they were lost to an encoding round-trip; replace them with explicit escapes such as `\u{10000}` and `\uFFFF`.

Standard Bash and host portability: 🟡 medium

Integer validation remains incompatible with ordinary host expr for valid large integers.

  • packages/just-bash/src/commands/expr/expr.ts:54 — Converting integer operands to binary64 loses precision for valid host `expr` integers: `expr 9007199254740992 = 9007199254740993` incorrectly returns true, while standard 64-bit GNU `expr` returns false. Use exact integer arithmetic or reject values outside the exact range.

Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call.

@privatenumber privatenumber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good:

  • ✅ Non-integer operands are rejected in arithmetic

    All five added arithmetic tests pass at head and fail at base. Comparison with GNU expr confirms the expected errors. expr.test.ts:5 · expr.ts:141 · :161

  • ✅ 2.5 = 2 is a string comparison

    The new test passes at head and returns 0 with exit status 1, matching GNU expr. expr.test.ts:20 · expr.ts:108

  • ✅ Signed integers like -1 are accepted

    Head returns 1 for the asserted expression with +2 and -1. GNU expr rejects the leading-plus operand, which is raised as a finding. expr.test.ts:25 · expr.ts:54

1 more
  • ✅ Focused expr regression tests all pass

    The repository's test runner reports seven tests at head, all passing. expr.test.ts:4

@vercel-internal-security-reviewer

Copy link
Copy Markdown

Security review details

@privatenumber privatenumber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good:

  • ✅ Arithmetic requires complete integer operands

    Both arithmetic parser branches validate operands with integerValue before calculating. The added decimal and partially numeric cases match GNU expr in comparison runs. expr.ts:53 · :163 · :185

  • ✅ Non-integer operands are compared as strings

    When either operand fails integerValue, equality compares the original strings and ordering uses compareStrings. The focused comparison examples match GNU expr. expr.ts:129 · :134

  • ✅ Focused expr regression tests pass

    The head version of expr.test.ts passes all 17 parameterized test cases in run_checks. expr.test.ts:4

    Not verified: the historical seven-test run.

1 more
  • ✅ String ordering compares Unicode code points

    compareStrings iterates code points and compares their numeric values, which preserves UTF-8 byte ordering for valid Unicode scalar values. expr.ts:68 · :70

    Not verified: locale behavior and invalid Unicode inputs.

@tanav29
tanav29 force-pushed the fix/expr-integer-operands branch from b0ad9ed to 7d84a2f Compare November 16, 2026 17:08
@tanav29

tanav29 commented Nov 16, 2026

Copy link
Copy Markdown
Author

@privatenumber I have gone through your suggestions and update the code as you suggested.

@privatenumber privatenumber added awaiting-review Maintainer review or re-review is next. Does not imply approval or merge readiness. bug Something isn't working commands Behavior of, or support for, individual commands p2 Normal backlog action. Priority is not acceptance or a delivery promise. labels Nov 20, 2026
@tanav29
tanav29 force-pushed the fix/expr-integer-operands branch from 7d84a2f to 4c26b4e Compare December 3, 2026 08:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review Maintainer review or re-review is next. Does not imply approval or merge readiness. bug Something isn't working commands Behavior of, or support for, individual commands p2 Normal backlog action. Priority is not acceptance or a delivery promise.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expr silently truncates decimal operands

2 participants