codeql: fix 4 integer-overflow findings + filter vendored SARIF#3112
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes several CodeQL-reported integer overflow / varargs issues in core C++ modules and adjusts the CodeQL workflow to post-filter SARIF so vendored/generated findings don’t remain open and dilute alert diffs.
Changes:
- Widened arithmetic in
string_repeatand audio limiter lookahead indexing to avoid 32-bit overflow. - Fixed potential
memcpylength overflows in raster channel-conversion fast paths. - Updated CodeQL workflow to generate SARIF without uploading, filter out vendored/generated paths, then upload the filtered SARIF.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tutorials/integration/c/14_passing_arrays.c | Fix printf varargs mismatch when printing a uint64_t array size. |
| src/builtin/module_builtin_string.cpp | Prevent 32-bit overflow when computing repeated string allocation size. |
| modules/dasStbImage/src/dasRaster.cpp | Use size_t math for memcpy byte counts in same-channel conversion paths. |
| modules/dasAudio/src/volume_mixer.h | Widen lookahead index arithmetic to avoid 32-bit overflow in frame indexing. |
| .github/workflows/codeql.yml | Add SARIF post-processing step to filter vendored/generated findings before upload. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ccd138f to
3bba88f
Compare
CodeQL c-cpp alerts on our own code (vendored/generated alerts handled
separately by the SARIF filter below):
- string_repeat: len*count was a 32-bit multiply feeding allocateString
(which takes uint64_t), so repeat(64KB-string, 65537) wrapped to a
tiny allocation while the copy loop wrote ~4GB past it — a
script-reachable heap overflow. Widen to uint64_t * uint64_t.
- dasRaster same-channel memcpy (3 sites): num_pixels*src_ch[*sizeof]
multiplied in int32 before promoting to the size_t length; wraps for
>2G-element images. Cast operands to size_t. (Only 2 were flagged;
the u8 path has the identical shape and is fixed too.)
- volume_mixer lookahead index: attack_samples*nChannels was a uint32
multiply inside otherwise-64-bit indexing. Cast to uint64_t.
- tutorial 14_passing_arrays.c: printf("%u", owned.size) on a uint64_t
field is varargs UB. Use %llu + cast.
Workflow: build-mode none does not honor the init paths-ignore for C/C++
results (a tests-cpp/3rdparty/doctest alert survived two master scans
with that config), so vendored/generated findings never auto-filtered.
Add a github/filter-sarif pass between analyze (upload:false) and
upload-sarif, dropping 3rdparty, stb_*.h, sqlite, minfft, and the frozen
v1 dasFormatter parser. src/parser generated lexers are NOT excluded —
our hand-written rule bodies live there. Dropped results auto-close
their alerts on the next master scan.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3bba88f to
92438a6
Compare
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Triage of the CodeQL c-cpp backlog (26 open alerts). 4 are real bugs in our own code — fixed here. The other 21 are vendored or generated; a SARIF filter (below) excludes them so they auto-close on the next master scan and stop diluting PR diffs. (PREfast's 16 C26819/C28251 alerts are style-class fallthrough/SAL nits, left as-is.)
Code fixes
string_repeatheap overflow (module_builtin_string.cpp) —len * countwas a 32-bit multiply feedingallocateString, which takesuint64_t.repeat(s, count)withlen*count > 4G(e.g. a 64KB string repeated 65537×) wrapped to a tiny allocation while the copy loop wrote ~4GB past it — script-reachable heap overflow. Widened touint64_t * uint64_t.memcpy(dasRaster.cpp, 3 sites) —num_pixels * src_ch [* sizeof(T)]multiplied inint32before promoting to thesize_tlength; wraps for >2G-element images. Operands cast tosize_t. CodeQL flagged the u16/f32 paths; the u8 path has the identical shape and is fixed too.attack_samples * nChannelswas auint32multiply inside otherwise-64-bit frame indexing. Cast touint64_t.printf("%u", owned.size)on auint64_tfield is a varargs type mismatch.%llu+ cast.Workflow: filter vendored / generated SARIF
build-mode: nonedoes not honor theinitpaths-ignorefor C/C++ results — atests-cpp/3rdparty/doctestalert survived two master scans with that config in place. So vendored findings never auto-filtered and sat in the Security tab (sqlite amalgamation + its CLI shell, stb headers, minfft, the frozen v1 dasFormatter bison parser, doctest).Added a
github/filter-sarifpass betweenanalyze(upload: false) andupload-sarif, excluding3rdparty,stb_*.h,modules/dasSQLITE/sqlite,modules/dasMinfft/minfft, andutils/dasFormatter/ds_parser.cpp.src/parsergenerated lexers are deliberately NOT excluded — our hand-written rule bodies live in them (that's exactly where the PVS OOB write in #3111 was hiding). Dropped results auto-close their alerts on the next master scan.Net after merge + next scan: all 26 CodeQL alerts clear (4 fixed, 21 filtered, plus the 5 alerts on the 4 fixed sites close as fixed).
Validation
repeat("ab",3)=="ababab",repeat("x",0)=="",repeat("",5)==""probedcpp.sarif) andfilter-sarif@v1usage follow the documented compiled-language pattern🤖 Generated with Claude Code