[FIX] Prevent NULL buffer dereference in WTV parser on oversized chunks#2255
[FIX] Prevent NULL buffer dereference in WTV parser on oversized chunks#2255ObaidAbdullah16 wants to merge 3 commits intoCCExtractor:masterfrom
Conversation
- Changed get_sized_buffer() to return int error code instead of void - Add error checks in all 5 callers before using cb->buffer - Gracefully handle malformed WTV files with chunk sizes > WTV_MAX_ALLOC (100MB) - Prevents segmentation fault when processing corrupted WTV input Root cause: Function returned without error signaling, leaving cb->buffer NULL. Callers then dereferenced NULL pointer causing crash. Fix: Return -1 on allocation/read failures, check return value in all callers. Test case: tests/samples/malformed_oversized_chunk.wtv triggers the original bug.
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit d56a6be...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
cfsmp3
left a comment
There was a problem hiding this comment.
Review
The defensive fix (changing get_sized_buffer() from void to int return) is a reasonable idea, but we can't merge this without a working reproduction.
Repro doesn't work
The Python script in the PR description creates a file starting with WTV\x00:
00000000 57 54 56 00 ...
But the actual WTV magic is 0xB7 0xD8 0x00 0x20 (the WTV_HEADER GUID in wtv_constants.h). CCExtractor never enters the WTV parser with the generated file. The included binary test file (malformed_oversized_chunk.wtv) has the same problem — same wrong magic bytes.
We tested with 5 real WTV samples and also tried hand-crafting files with the correct magic + oversized chunk lengths — the WTV parser exits early without hitting the vulnerable path.
Without a real reproduction that demonstrates the crash, we won't merge this. Please provide either:
- A real WTV file that crashes ccextractor, or
- A script that generates a file with the correct WTV header structure that actually triggers
get_sized_buffer()with an oversized length
Other issues to fix if you resubmit
- Hardcoded line numbers in error messages (
"line 367","line 426", etc.) will go stale when anyone edits the file. Use__LINE__or just remove them. - Binary test file — don't include it in the repo, especially since it doesn't work. The Python script to generate it is sufficient.
- Redundant checks — every caller already had
if (cb->buffer == NULL) return CCX_EOF;after the call. The new return code check duplicates this. Consider removing the redundant NULL checks if you're using the return code. - New header file —
wtv_functions.his missing a trailing newline, andwtv_functions.cdoesn't include it (still uses forward declarations).
What works
- 5 real WTV samples produce byte-identical output on master and this PR — no regressions.
- The code change itself is clean and the return-code pattern is correct.
Thanks for the effort — just need the repro fixed.
[FIX]
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Repro instructions:
I found a crash in the WTV parser when processing malformed files with oversized chunk headers. The issue happens when a WTV file claims a chunk is larger than 100MB (WTV_MAX_ALLOC). The parser sets the buffer to NULL but doesn't signal an error, so the callers try to use a NULL pointer and crash.
To reproduce:
Run:
ccextractor malformed.wtv -o output.srtBefore fix: Segmentation fault
After fix: Error message printed, no crash
The fix changes
get_sized_buffer()fromvoidtointand returns -1 on errors. All 5 callers now check the return value before accessing the buffer.Sample file included:
tests/samples/malformed_oversized_chunk.wtvSummary
This fixes a crash in the WTV demuxer that happens when a malformed file has a chunk header claiming more than 100MB of data. Instead of crashing, the parser now prints an error message and continues safely.
The root issue was that
get_sized_buffer()had no way to signal errors to its callers. Now it returns an error code, and all callers check for it.Root Cause
get_sized_buffer()returnedvoid(no error signaling mechanism)cb->buffer = NULLand returned silentlycb->bufferwithout NULL checksChanges Made
get_sized_buffer()to returnint(error code) instead ofvoidcb->buffer:src/lib_ccx/wtv_functions.hwith function declarationstests/samples/malformed_oversized_chunk.wtvto trigger the bugFiles Modified
src/lib_ccx/wtv_functions.c- Updated function signature and all 5 callerssrc/lib_ccx/wtv_functions.h- New header file with declarationstests/samples/malformed_oversized_chunk.wtv- Test case for malformed inputTesting
Type
Security/Robustness fix - prevents crashes when processing corrupted or malicious WTV files