Skip to content

DynArray::EnsureCapacity: make the overflow check survive release builds#1089

Open
Gooh456 wants to merge 1 commit into
leethomason:masterfrom
Gooh456:fix-dynarray-overflow-release-1065
Open

DynArray::EnsureCapacity: make the overflow check survive release builds#1089
Gooh456 wants to merge 1 commit into
leethomason:masterfrom
Gooh456:fix-dynarray-overflow-release-1065

Conversation

@Gooh456

@Gooh456 Gooh456 commented Jul 24, 2026

Copy link
Copy Markdown

Looked into #1065. The overflow guard on cap * 2 is a TIXMLASSERT, which is a no-op outside TINYXML2_DEBUG — so in release an overflowing cap wraps newAllocated to something tiny, new T[newAllocated] succeeds with an undersized buffer, and the memcpy right after writes past it. Added a real check ahead of the multiply, left the existing assert for the debug diagnostic. Reaching the overflow boundary needs cap near SIZE_MAX/2/sizeof(T), so this is mostly hardening, not something a normal document hits — same conclusion the reporter came to.

Fixes #1065. I don't have a build environment to compile-verify this locally — flagging that so it gets an extra look in CI/review rather than assuming it's clean.

Signed-off-by: Kyue <164024549+Gooh456@users.noreply.github.com>
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.

Security: Integer Overflow and Heap Buffer Overflow in DynArray::EnsureCapacity

1 participant