Skip to content

array: validate skip/count before array copy sizing#510

Merged
ptitSeb merged 1 commit into
ptitSeb:masterfrom
orbisai0security:fix-v002-array-underflow
May 21, 2026
Merged

array: validate skip/count before array copy sizing#510
ptitSeb merged 1 commit into
ptitSeb:masterfrom
orbisai0security:fix-v002-array-underflow

Conversation

@orbisai0security
Copy link
Copy Markdown
Contributor

@orbisai0security orbisai0security commented May 21, 2026

This defensively validates skip and count before array-copy helpers
compute allocation or memcpy sizes from (count - skip).

Several helpers in src/gl/array.c use this expression when allocating or
copying converted vertex/color/texcoord data. If invalid ranges are ever
propagated into these helpers, the subtraction can underflow or produce
incorrect copy sizes.

This patch adds a shared valid_copy_range() helper and applies it
consistently at the top of each affected function:

  • copy_gl_array
  • copy_gl_array_texcoord
  • copy_gl_array_quickconvert
  • copy_gl_array_convert
  • copy_gl_array_bgra

Behavior is unchanged for valid inputs; invalid ranges are rejected early.

@ptitSeb
Copy link
Copy Markdown
Owner

ptitSeb commented May 21, 2026

While the fix itself is ok, it's really either to restriected (there are many other similar functions in the code), or not applied in the right place (most functions calls this with skip=0, but it's also used by other copy_gl_array_XXX functions that might also need a check in that case).

I will not accept the PR in it's current form.

@orbisai0security orbisai0security changed the title fix: the vertex array copy function computes memcpy ... in array.c array: validate skip/count before array copy sizing May 21, 2026
Defensively validate skip and count before array-copy helpers compute
allocation or memcpy sizes from (count - skip).

Several helpers in src/gl/array.c use this expression when allocating or
copying converted vertex/color/texcoord data. If invalid ranges are ever
propagated into these helpers, the subtraction can underflow or produce
incorrect copy sizes.

Add a shared valid_copy_range() helper and apply it consistently at the
top of each affected function:
- copy_gl_array
- copy_gl_array_texcoord
- copy_gl_array_quickconvert
- copy_gl_array_convert
- copy_gl_array_bgra

Behavior is unchanged for valid inputs; invalid ranges are rejected early.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@orbisai0security orbisai0security force-pushed the fix-v002-array-underflow branch from 666d918 to ee11526 Compare May 21, 2026 08:21
@orbisai0security
Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I agree this should not be fixed narrowly in only copy_gl_array.

I've reworked this as a defensive bounds-hardening change across all the related array-copy helpers. The revised patch adds a shared valid_copy_range() helper and checks the skip/count invariant consistently before any (count - skip) allocation/copy arithmetic, covering:

  • copy_gl_array
  • copy_gl_array_texcoord
  • copy_gl_array_quickconvert
  • copy_gl_array_convert
  • copy_gl_array_bgra

I've also updated the PR title and description to frame this as what it is — defensive bounds hardening — rather than overstating the severity. Behavior is unchanged for valid inputs.

@ptitSeb
Copy link
Copy Markdown
Owner

ptitSeb commented May 21, 2026

Ok, looks better now.

@ptitSeb ptitSeb merged commit ca13030 into ptitSeb:master May 21, 2026
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