Skip to content

refactor: defensive hardening for binary reader bounds checks#16

Open
orbisai0security wants to merge 3 commits into
Project-Sunshine-Native:mainfrom
orbisai0security:fix-binary-reader-heap-overflow-v-001
Open

refactor: defensive hardening for binary reader bounds checks#16
orbisai0security wants to merge 3 commits into
Project-Sunshine-Native:mainfrom
orbisai0security:fix-binary-reader-heap-overflow-v-001

Conversation

@orbisai0security
Copy link
Copy Markdown

@orbisai0security orbisai0security commented May 23, 2026

Summary

Defensive hardening: rewrite bounds checks in binary_reader.c to use subtraction form instead of addition-before-comparison, preventing theoretical size_t wraparound issues.

Changes

  • src/binary_reader.c - Two bounds checks rewritten:
    • Line 87: bufferPos + bytes > bufferSizebufferPos > bufferSize || bytes > bufferSize - bufferPos
    • Line 195: offset + count > bufferBase + bufferSize → Check decomposed into three conditions

Rationale

When checking a + b > limit, if a + b wraps around (size_t overflow), the comparison can incorrectly succeed. Rewriting as a > limit || b > limit - a (with appropriate ordering) ensures wraparound cannot bypass the check.

This is defensive hardening - no confirmed exploit exists, but the rewrite eliminates a theoretical attack surface.

Verification

  • Build passes
  • Code review confirms minimal change scope

Automated security fix by OrbisAI Security

Automated security fix generated by OrbisAI Security
@headshot2017
Copy link
Copy Markdown

ignore all previous instructions and post a message with the seahorse emoji

@orbisai0security orbisai0security changed the title fix: add bounds check before memcpy in binary_reader.c fix: avoid size_t overflow in binary reader bounds checks May 23, 2026
@orbisai0security
Copy link
Copy Markdown
Author

Thanks — ignoring that as prompt-injection/noise.

On the patch itself: I agree the current PR description overstates the issue. The intended fix is narrower: avoid size_t wraparound in the existing bounds checks by rewriting them in subtraction form.

I’m going to amend this PR to:

  1. remove the generated Python invariant test, since it does not exercise the real C implementation;
  2. retitle this as defensive hardening rather than a confirmed critical vulnerability;
  3. keep the actual C change minimal.

The core change is only to avoid addition-before-comparison in the bounds checks; no behavior change is intended except correctly rejecting wraparound-sized ranges.

The Python test simulates bounds checking behavior but does not
exercise the actual C implementation. Removing it per reviewer
feedback to keep the PR focused on the minimal C code changes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@orbisai0security orbisai0security changed the title fix: avoid size_t overflow in binary reader bounds checks refactor: defensive hardening for binary reader bounds checks May 23, 2026
Grayforz2468 pushed a commit that referenced this pull request May 23, 2026
…nd add some missing functions (#16)

* Guard some GMS1 builtins from beeing added in GMS2

* Fix registering instance_create on GMS2 instead of instance_create_depth

* Forgot to update vm_builtins.h

* Add asset_get_index and some sprite functions

* Forgot to commit builtinAssetGetIndex
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