mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-04-20 21:20:28 +00:00
[PR #1792] fix(matroska): add memory safety checks and fix memory leaks #2526
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1792
State: closed
Merged: Yes
Summary
This PR addresses multiple memory safety issues in the Matroska parser (
src/lib_ccx/matroska.c) identified through static analysis using cppcheck.Issues Fixed
Details
Null pointer dereference after malloc (15 fixes)
malloc/calloccallsEXIT_NOT_ENOUGH_MEMORY(exit code 500) for OOM conditionsBuffer overflow fixes (3 fixes)
generate_timestamp_ass_ssa(): Buffer 15→32 bytes, sprintf→snprintfsave_sub_track(): number[] buffer 9→16 bytes, sprintf→snprintfgenerate_filename_from_track(): Dynamic buffer size calculationMemory leak fixes (7 fixes)
read_vint_block_string()return values inparse_ebml()andparse_segment_info()parse_segment_track_entry()wherelangwas reassigned without freeingsave_sub_track()where text pointer was advanced, losing original allocationRealloc error handling (3 fixes)
Use-after-free fix (1 fix)
matroska_loop(): Saved values beforematroska_free_all(), then used saved valuesMissing free fixes (2 fixes)
free(track->sentences)infree_sub_track()free(mkv_ctx->sub_tracks)inmatroska_free_all()Test plan
🤖 Generated with Claude Code