You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Veracode Flaw (static): Numeric Errors in 5.4.0 #3050
This issue is a follow-up to my previous issue #2925.
We would like to move to the latest jemalloc 5.4.0 which included Veracode fixes for issues found in 5.3.1 but our latest Veracode scan of 5.4.0 has found an issue in jemalloc.c:1137:
This arithmetic operation results in an integer overflow error. Because the result of this calculation is larger than the maximum possible value for this data type, the result may wrap to become a very small, or negative number, therefore providing an unintended value. Integer overflows can often trigger buffer overflows, which can be exploited to execute arbitrary code.
Is it possible to fix this error and release a patched version of 5.4.0 please?
@spredolac unfortunately the latest Veracode scan on that PR has found another issue in rtree.c:299 (though I see this code hasn't changed since the last scan?). The original issue is fixed though.
@brookheather , thanks, Do you have a expanded path or more details (if you can click on that Data Path column where it says "1 path" and send me expanded text it would be helpful)?
Thanks, the additional details confirm the finding concerns the L2 cache memmove (which is what we suspected).
The reported memmove appears correctly bounded to us and our tools. l2_cache is declared as rtree_ctx_cache_elm_tl2_cache[RTREE_CTX_NCACHE_L2], with RTREE_CTX_NCACHE_L2 = 8. The operation copies seven entries from indices 0–6 to 1–7, entirely within that array; memmove supports the overlap.
On a typical 64-bit build, this is a 112-byte copy into 112 bytes of remaining array space. The stack fallback contains the complete rtree_ctx_t object and remains alive throughout the lookup. The copy length is compile-time constant and independent of runtime input.
Could Veracode review finding 14 / CWE-121 as a potential false positive and provide the destination size and copy length inferred by its analysis? I suspect not, but wanted to check. Without further evidence of an overflow, I would prefer to keep memmove, since it expresses the intent more clearly than a loop.
I have raised a false positive review with Veracode using your analysis - I will inform you of their reply. Would it make much difference to just use a loop here?
This gets auto-closed when I merge associated PR. So, loop would be semantically equivalent and compiler would in some cases generate exactly the same code (on my server it did for something like this)
for (unsigned i = RTREE_CTX_NCACHE_L2 - 1; i > 0; --i) {
rtree_ctx->l2_cache[i] = rtree_ctx->l2_cache[i - 1];
}
Activity
spredolac commentedon Oct 23, 2026
@brookheather , any chance you can test the attached PR and if it fails can you attach the full trace ? Thanks
brookheather commentedon Oct 27, 2026
@spredolac unfortunately the latest Veracode scan on that PR has found another issue in rtree.c:299 (though I see this code hasn't changed since the last scan?). The original issue is fixed though.
spredolac commentedon Oct 27, 2026
@brookheather , thanks, Do you have a expanded path or more details (if you can click on that Data Path column where it says "1 path" and send me expanded text it would be helpful)?
brookheather commentedon Oct 27, 2026
This is all I see under the data path:

spredolac commentedon Oct 27, 2026
Thanks, the additional details confirm the finding concerns the L2 cache
memmove(which is what we suspected).The reported memmove appears correctly bounded to us and our tools.
l2_cacheis declared asrtree_ctx_cache_elm_tl2_cache[RTREE_CTX_NCACHE_L2], withRTREE_CTX_NCACHE_L2 = 8. The operation copies seven entries from indices0–6 to 1–7,entirely within that array; memmove supports the overlap.On a typical 64-bit build, this is a 112-byte copy into 112 bytes of remaining array space. The stack fallback contains the complete
rtree_ctx_tobject and remains alive throughout the lookup. The copy length is compile-time constant and independent of runtime input.Could Veracode review finding 14 / CWE-121 as a potential false positive and provide the destination size and copy length inferred by its analysis? I suspect not, but wanted to check. Without further evidence of an overflow, I would prefer to keep memmove, since it expresses the intent more clearly than a loop.
brookheather commentedon Oct 28, 2026
I have raised a false positive review with Veracode using your analysis - I will inform you of their reply. Would it make much difference to just use a loop here?
Use internal alignment logarithm in free_aligned_sized
Use internal alignment logarithm in free_aligned_sized
spredolac commentedon Oct 29, 2026
This gets auto-closed when I merge associated PR. So, loop would be semantically equivalent and compiler would in some cases generate exactly the same code (on my server it did for something like this)
but we find
expressing intent a bit more clearly.