Skip to content

Fix unsigned integer underflow in WAV header ChunkSize parsing - #815

Open
MarkRose wants to merge 1 commit into
sm0svx:masterfrom
MarkRose:fix-msghandler-wav-underflow
Open

Fix unsigned integer underflow in WAV header ChunkSize parsing#815
MarkRose wants to merge 1 commit into
sm0svx:masterfrom
MarkRose:fix-msghandler-wav-underflow

Conversation

@MarkRose

Copy link
Copy Markdown
Contributor
  • In WavFileQueueItem::initialize() (MsgHandler.cpp), the RIFF ChunkSize
    field is a uint32_t. The subchunk-parsing loop computed
    rest_size = chunk_size - 4 in unsigned arithmetic before assigning it
    to the signed int64_t rest_size. A WAV file with a ChunkSize smaller
    than 4 (e.g. 0-3) caused this subtraction to wrap around to a huge
    unsigned value (~4.29e9), which was then stored as a large positive
    rest_size, driving the subchunk-reading loop far beyond what the file
    actually contains instead of being rejected as malformed. The fix
    validates that chunk_size is at least 4 before subtracting, returning
    false with a warning otherwise, and performs the subtraction in signed
    64-bit arithmetic.

Co-Authored-By: Claude Opus 4.8 [email protected]


This PR also adds a unit test (MsgHandlerWavChunkSizeTest.cpp). It is auto-discovered and executed by the CTest suite proposed in #762 once that is merged; without that suite present the test file is inert and does not affect the build.

- In WavFileQueueItem::initialize() (MsgHandler.cpp), the RIFF ChunkSize
  field is a uint32_t. The subchunk-parsing loop computed
  `rest_size = chunk_size - 4` in unsigned arithmetic before assigning it
  to the signed int64_t rest_size. A WAV file with a ChunkSize smaller
  than 4 (e.g. 0-3) caused this subtraction to wrap around to a huge
  unsigned value (~4.29e9), which was then stored as a large positive
  rest_size, driving the subchunk-reading loop far beyond what the file
  actually contains instead of being rejected as malformed. The fix
  validates that chunk_size is at least 4 before subtracting, returning
  false with a warning otherwise, and performs the subtraction in signed
  64-bit arithmetic.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@MarkRose MarkRose closed this Jul 12, 2026
@MarkRose MarkRose reopened this Jul 12, 2026
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.

1 participant