mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-07-08 18:06:30 +00:00
[PR #1796] [MERGED] fix(ccx_decoders_common): add NULL checks and fix memory safety issues #2533
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?
📋 Pull Request Information
Original PR: https://github.com/CCExtractor/ccextractor/pull/1796
Author: @cfsmp3
Created: 12/12/2025
Status: ✅ Merged
Merged: 12/13/2025
Merged by: @cfsmp3
Base:
master← Head:fix/ccx-decoders-common-memory-leaks📝 Commits (1)
1c955d5fix(ccx_decoders_common): add NULL checks and fix memory safety issues📊 Changes
1 file changed (+95 additions, -13 deletions)
View changed files
📝
src/lib_ccx/ccx_decoders_common.c(+95 -13)📄 Description
Summary
This PR fixes multiple memory safety issues in
src/lib_ccx/ccx_decoders_common.c:Bug Fixes
1. Buffer Overflows in
copy_encoder_context()(Critical)String allocations were missing
+1for the null terminator, causing buffer overflows when copying:first_input_file- allocatedstrlen()bytes but copiedstrlen()bytes (should bestrlen() + 1)start_credits_text- allocatedstrlen()bytes butmemcpycopiedstrlen() + 1bytesend_credits_text- allocatedstrlen()bytes butmemcpycopiedstrlen() + 1bytesBefore:
After:
2. Missing NULL Checks After malloc (High)
Added NULL checks with
fatal(EXIT_NOT_ENOUGH_MEMORY, ...)calls (following the pattern inmatroska.c) in:init_cc_decode()- 6 allocations now checkedcopy_encoder_context()- 9 allocations now checkedcopy_decoder_context()- 8 allocations now checkedcopy_subtitle()- 2 allocations now checked3. Potential NULL Pointer Dereference in
init_cc_decode()(High)Line
ctx->dtvcc->is_active = setting->settings_dtvcc->enabled;would crash ifdtvcc_init()returned NULL. Now properly checked before dereferencing.4. Stale Pointer Prevention
After
memcpy()copies the source structure, the copied pointers point to the original's memory. These are now explicitly set to NULL before re-allocation to prevent accidental use of stale pointers.Functions Modified
init_cc_decode()copy_encoder_context()copy_decoder_context()copy_subtitle()Test plan
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.