Skip to content

fix signed overflow when multiplying array dimensions - #9027

Open
Nussu06 wants to merge 1 commit into
cppcheck-opensource:mainfrom
Nussu06:array-dimensions-overflow
Open

Nussu06 wants to merge 1 commit into
cppcheck-opensource:mainfrom
Nussu06:array-dimensions-overflow

Conversation

@Nussu06

@Nussu06 Nussu06 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

CheckBufferOverrunImpl::getBufferSize, accumulateStructMembers (used by ValueType::getSizeOf) and setValues in clangimport multiply the array dimensions of a variable in MathLib::bigint without an overflow check, so a declaration like char a[0x100000000][0x100000000]; in the checked code makes cppcheck run into signed integer overflow (UBSan at checkbufferoverrun.cpp:635 and symboldatabase.cpp:8702). When the product wraps to a small value the results are wrong as well: for char a[0x4000000000000001][4]; memset(a, 0, 10); cppcheck reports bufferAccessOutOfBounds, and sizeof of a struct holding that array is folded to 4. Added Variable::dimensionsProduct, which reports the overflow, and all three sites now treat an overflowing product as an unknown size; sizes that fit are unchanged. TestBufferOverrun::arraysize_overflow and a new case in TestValueFlow::valueFlowSizeof fail without the change, the full testrunner passes, and TestBufferOverrun, TestValueFlow and TestClangImport also pass in a build with -fsanitize=signed-integer-overflow. I don't have Trac access, could one of you create a ticket for this so I can reference it in the title?

@dmcppcheck

Copy link
Copy Markdown
Contributor

There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated.

@Nussu06

Nussu06 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

hey can anyone create trac ticket for this pr, thanks.

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