Skip to content

fix(node:buffer): reject negative allocation size#2274

Merged
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-buffer-alloc-negative-size
May 28, 2026
Merged

fix(node:buffer): reject negative allocation size#2274
proggeramlug merged 1 commit into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-buffer-alloc-negative-size

Conversation

@andrewtdiz
Copy link
Copy Markdown
Contributor

Summary:

  • Throw RangeError with ERR_OUT_OF_RANGE for negative Buffer allocation sizes.
  • Apply the check before Buffer.alloc, filled Buffer.alloc, and Buffer.allocUnsafe allocation paths.
  • Buffer.allocUnsafeSlow shares the unsafe allocation helper, so it gets the same validation.

Part of #793.

Evidence:

  • Baseline exact ./run_parity_tests.sh --suite node-suite --filter node-suite/buffer/allocation/alloc-fill-typedarray: FAIL, report test-parity/reports/parity_report_20260528_104915.json.
  • Final exact ./run_parity_tests.sh --suite node-suite --filter node-suite/buffer/allocation/alloc-fill-typedarray: PASS, report test-parity/reports/parity_report_20260528_105240.json.
  • Allocation subgroup ./run_parity_tests.sh --suite node-suite --module buffer/allocation: PASS 9/9, report test-parity/reports/parity_report_20260528_105327.json.
  • Full granular ./run_parity_tests.sh --suite node-suite --module buffer: 104 PASS / 11 parity FAIL / 1 compile FAIL, report test-parity/reports/parity_report_20260528_105340.json; allocation is green. buffer/concat/edge-lengths remains red on this branch because it is fixed separately in open PR fix(node:buffer): honor concat total length #2271. Other residuals remain in byteLength edge encodings, compare bounds, fill/write coercions, Buffer.from coercions/errors, inspect limits, iterator, range-error edge cases, and ucs2 search compile behavior.
  • cargo check -p perry-runtime -p perry-stdlib -p perry-codegen: PASS with existing warnings.
  • cargo fmt --check: PASS.
  • jq empty test-parity/known_failures.json: PASS.
  • git diff --check: PASS.

DeepWiki:

  • Local-only reference: reference/deepwiki/nodejs-node-buffer-alloc-negative-size-2026-05-28.md.

Non-goals:

  • No maximum allocation length validation.
  • No non-integer size coercion cleanup.
  • No Uint8Array/ArrayBuffer constructor validation.
  • No adjacent Buffer.from/write/fill coercion work.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants