Skip to content

Reject overflowing integers in bytecode reader - #553

Open
carrerasdarren-cell wants to merge 1 commit into
bellard:masterfrom
carrerasdarren-cell:agent/validate-bytecode-counts
Open

Reject overflowing integers in bytecode reader#553
carrerasdarren-cell wants to merge 1 commit into
bellard:masterfrom
carrerasdarren-cell:agent/validate-bytecode-counts

Conversation

@carrerasdarren-cell

Copy link
Copy Markdown

Summary

Problem

bc_get_leb128_int() previously wrote an unsigned LEB128 value directly through an int *. Values above INT_MAX therefore became negative. In JS_ReadFunctionTag(), a negative count could wrap the allocation-size calculation below the bytecode-function header size before the header copy.

The shared decoder now raises a SyntaxError for values that cannot be represented by its positive int callers. This also removes the incompatible pointer cast.

Fixes #549.

Testing

  • make -j4 test
  • make -j4 CONFIG_ASAN=y CONFIG_UBSAN=y test
  • exact 21-byte reproducer: baseline reports a 96-byte heap-buffer-overflow write; patched build rejects it with SyntaxError: integer overflow while reading bytecode

Decode positive int fields through a uint32_t temporary and reject values above INT_MAX before assigning them. This prevents malformed counts from wrapping allocation-size calculations in JS_ReadFunctionTag. Add a binary-object regression for the overflowing constant-pool count from issue bellard#549.
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.

[Bug]Heap-buffer-overflow WRITE in JS_ReadFunctionTag: negative count wraps the allocation size below the header size (CWE-787)

1 participant