[PR #1807] fix(lib_ccx): replace unsafe string functions with bounds-checked versions #2548

Open
opened 2026-01-29 17:22:43 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/1807

State: closed
Merged: Yes


Summary

Replace sprintf/strcpy/strcat with bounds-checked versions in files identified in Phase 3.1 of the buffer safety audit. This completes all dangerous function pattern fixes.

Files Modified

Medium Priority (previous commit)

File Changes
ccx_encoders_common.c 4 sprintf → snprintf
ccx_encoders_helpers.c 3 strcat → strncat, 1 strcpy → memcpy
telxcc.c 3 sprintf → snprintf
asf_functions.c 3 sprintf → snprintf
ccx_encoders_ssa.c 3 sprintf → snprintf
ccx_encoders_curl.c 1 sprintf → snprintf, strcpy+strcat → snprintf with OOM check
ccx_encoders_splitbysentence.c 1 strcpy → memmove (overlapping memory fix), 2 strcat → strncat

Low Priority (latest commit)

File Changes
general_loop.c Proper buffer allocation with OOM check, snprintf
ccx_encoders_g608.c snprintf with sizeof for timeline buffer
lib_ccx.c Fix buffer size calculation (was 2 bytes short), add missing null check, snprintf
ccx_common_timing.c snprintf with documented max size for time functions
ts_functions.c snprintf with sizeof in debug code
matroska.c Bounded memcpy to prevent overflow from malformed language codes
output.c snprintf with known allocated size

Notable Fixes

  1. ccx_encoders_splitbysentence.c: Fixed undefined behavior where strcpy() was used with overlapping memory regions. Replaced with memmove().

  2. ccx_encoders_curl.c: Added OOM check for malloc allocation that was previously unchecked.

  3. lib_ccx.c: Fixed buffer size calculation - was allocating strlen + 10 but needed strlen + 12 for the format string.

  4. matroska.c: Protected against malformed language codes that could cause buffer overflow from untrusted file input.

Test plan

  • Builds successfully on Linux
  • CI tests pass

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1807 **State:** closed **Merged:** Yes --- ## Summary Replace sprintf/strcpy/strcat with bounds-checked versions in files identified in Phase 3.1 of the buffer safety audit. This completes all dangerous function pattern fixes. ### Files Modified #### Medium Priority (previous commit) | File | Changes | |------|---------| | ccx_encoders_common.c | 4 sprintf → snprintf | | ccx_encoders_helpers.c | 3 strcat → strncat, 1 strcpy → memcpy | | telxcc.c | 3 sprintf → snprintf | | asf_functions.c | 3 sprintf → snprintf | | ccx_encoders_ssa.c | 3 sprintf → snprintf | | ccx_encoders_curl.c | 1 sprintf → snprintf, strcpy+strcat → snprintf with OOM check | | ccx_encoders_splitbysentence.c | 1 strcpy → memmove (overlapping memory fix), 2 strcat → strncat | #### Low Priority (latest commit) | File | Changes | |------|---------| | general_loop.c | Proper buffer allocation with OOM check, snprintf | | ccx_encoders_g608.c | snprintf with sizeof for timeline buffer | | lib_ccx.c | Fix buffer size calculation (was 2 bytes short), add missing null check, snprintf | | ccx_common_timing.c | snprintf with documented max size for time functions | | ts_functions.c | snprintf with sizeof in debug code | | matroska.c | Bounded memcpy to prevent overflow from malformed language codes | | output.c | snprintf with known allocated size | ### Notable Fixes 1. **ccx_encoders_splitbysentence.c**: Fixed undefined behavior where `strcpy()` was used with overlapping memory regions. Replaced with `memmove()`. 2. **ccx_encoders_curl.c**: Added OOM check for malloc allocation that was previously unchecked. 3. **lib_ccx.c**: Fixed buffer size calculation - was allocating `strlen + 10` but needed `strlen + 12` for the format string. 4. **matroska.c**: Protected against malformed language codes that could cause buffer overflow from untrusted file input. ## Test plan - [x] Builds successfully on Linux - [ ] CI tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:22:43 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2548