Skip to content

Fix numeric overflow checks in size classes - #2926

Merged
spredolac merged 1 commit into
jemalloc:devfrom
spredolac:numeric_errors_issue_2925
May 27, 2026
Merged

spredolac merged 1 commit into
jemalloc:devfrom
spredolac:numeric_errors_issue_2925

Conversation

@spredolac

Copy link
Copy Markdown
Contributor

This should address issue #2925

I do not have veracode to run locally, but based on description this should fit.
This change does not affect the ordinary malloc() fast path. sz_sa2u() logic is only reached for aligned allocations.

SC_LARGE_MAXCLASS is expressed as pointer-width constant instead of macro arithmetic. configure.ac only supports LG_SIZEOF_PTR == 2 or 3 (32-bit or 64-bit pointers, with the same MSVC mapping), so the constants are equivalent while avoiding arithmetic expansion at jemalloc.c use sites (one of them most likely reported by veracode).

For sz_sa2u(), zero alignment now returns 0 before computing alignment - 1. Power-of-two alignment is internal caller contract enforced by the existing assert in debug build (all current callers respect it by either validating alignment, deriving it fromMALLOCX_ALIGN_GET(), or passing known power-of-two constants).

New tests fail before the change.

@spredolac
spredolac force-pushed the numeric_errors_issue_2925 branch from be086ac to cccef0b Compare May 26, 2026 20:21

@guangli-dai guangli-dai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, since CI is green, we can merge once @brookheather confirms that it passes Veracode checks.

@brookheather

Copy link
Copy Markdown

Thanks for the quick response however I will need a branch or tag with this change in it to download it on our side (internally I need to provide just a URL) and then I can get it scanned with Veracode.

@spredolac

Copy link
Copy Markdown
Contributor Author

I will merge into dev then as changes are okay in any case. We will not close your issue until you confirm.

@spredolac
spredolac merged commit 6b24522 into jemalloc:dev May 27, 2026
154 checks passed
@brookheather

Copy link
Copy Markdown

We have run Veracode on the latest dev branch and unfortunately the Integer Overflow error is still present on sz.h:331 and there is now an additional Integer Overflow error on sz.h:361 so the latest code is actually worse it seems. I think sz.h:331 will need to be rewritten.

Lines sz.h:331 and sz.h:421 also have an Integer Underflow error.

image

@spredolac
spredolac deleted the numeric_errors_issue_2925 branch June 6, 2026 14:26
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.

3 participants