Skip to content

lib: fix modulo sign in webidl convertToInt#62940

Draft
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix:deepview/415d17df0c
Draft

lib: fix modulo sign in webidl convertToInt#62940
deepview-autofix wants to merge 1 commit intonodejs:mainfrom
deepview-autofix:deepview/415d17df0c

Conversation

@deepview-autofix
Copy link
Copy Markdown

@deepview-autofix deepview-autofix commented Apr 24, 2026

The modulo() helper in lib/internal/webidl.js is documented to implement ECMA-262's "x modulo y" (result has the same sign as y), but it used the JS % operator directly, whose result takes the sign of x. convertToInt step 10 relies on modulo(x, 2^bitLength) producing a non-negative representative in [0, 2^bitLength); step 11 only handles the signed upper half, so negative results of % were returned unchanged.

As a result, negative inputs to unsigned WebIDL integer types returned the original negative value instead of the two's-complement wrap (e.g. convertToInt('v', -3, 8) returned -3 instead of 253), and signed inputs in the one-wrap band below the lower bound were returned as-is (convertToInt('v', -200, 8, { signed: true }) returned -200 instead of 56). This diverged from typed-array coercion.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 24, 2026
Copy link
Copy Markdown
Member

@ChALkeR ChALkeR left a comment

Choose a reason for hiding this comment

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

This is mine

Copy link
Copy Markdown
Member

@ChALkeR ChALkeR left a comment

Choose a reason for hiding this comment

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

@ChALkeR ChALkeR force-pushed the deepview/415d17df0c branch from 65d51ec to cae7693 Compare April 24, 2026 23:56
@ChALkeR ChALkeR dismissed their stale review April 24, 2026 23:56

fixed

@ChALkeR ChALkeR force-pushed the deepview/415d17df0c branch from cae7693 to 34e138f Compare April 25, 2026 00:00
The modulo() helper in lib/internal/webidl.js is documented to implement
ECMA-262's "x modulo y" (result has the same sign as y), but it used the
JS % operator directly, whose result takes the sign of x. convertToInt
step 10 relies on modulo(x, 2^bitLength) producing a non-negative
representative in [0, 2^bitLength); step 11 only handles the signed
upper half, so negative results of % were returned unchanged.

As a result, negative inputs to unsigned WebIDL integer types returned
the original negative value instead of the two's-complement wrap (e.g.
convertToInt('v', -3, 8) returned -3 instead of 253), and signed inputs
in the one-wrap band below the lower bound were returned as-is
(convertToInt('v', -200, 8, { signed: true }) returned -200 instead of
56). This diverged from typed-array coercion.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com>
Co-Authored-By: Nikita Skovoroda <chalkerx@gmail.com>
Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Nikita Skovoroda <chalkerx@gmail.com>
@ChALkeR ChALkeR force-pushed the deepview/415d17df0c branch from 34e138f to 0f245d2 Compare April 25, 2026 00:18
@ChALkeR ChALkeR marked this pull request as draft April 25, 2026 01:14
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.58%. Comparing base (4744070) to head (0f245d2).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62940      +/-   ##
==========================================
- Coverage   89.66%   89.58%   -0.08%     
==========================================
  Files         706      706              
  Lines      219370   219216     -154     
  Branches    42065    41954     -111     
==========================================
- Hits       196694   196384     -310     
- Misses      14586    14729     +143     
- Partials     8090     8103      +13     
Files with missing lines Coverage Δ
lib/internal/webidl.js 96.75% <100.00%> (+0.02%) ⬆️

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ChALkeR
Copy link
Copy Markdown
Member

ChALkeR commented Apr 25, 2026

Calculation at 64 bits is still off, will redo

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

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants