[PR #1801] fix(smptett): replace unsafe string operations with bounds-checked versions #2540

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

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

State: closed
Merged: Yes


Summary

  • Replace all sprintf, strcpy, and strcat calls with bounds-checked versions
  • Add NULL checks after malloc allocations
  • Prevent potential buffer overflows in SMPTE Timed Text encoder

Changes

Function Change
write_stringz_as_smptett Use snprintf with sizeof(str) for timestamp formatting
write_cc_bitmap_as_smptett Use snprintf with INITIAL_ENC_BUFFER_CAPACITY
write_cc_buffer_as_smptett Major rewrite:
- Add NULL checks for final and temp malloc
- Track buf_size and use throughout
- Replace strcpy/strcat chains with memcpy/snprintf
- Use snprintf for style tags and color code formatting

Test plan

  • Build succeeds without errors
  • Verify SMPTE-TT output format is unchanged for basic subtitles
  • Verify styled subtitles (italic, bold, underline) render correctly
  • Verify font color subtitles render correctly

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1801 **State:** closed **Merged:** Yes --- ## Summary - Replace all `sprintf`, `strcpy`, and `strcat` calls with bounds-checked versions - Add NULL checks after malloc allocations - Prevent potential buffer overflows in SMPTE Timed Text encoder ## Changes | Function | Change | |----------|--------| | `write_stringz_as_smptett` | Use `snprintf` with `sizeof(str)` for timestamp formatting | | `write_cc_bitmap_as_smptett` | Use `snprintf` with `INITIAL_ENC_BUFFER_CAPACITY` | | `write_cc_buffer_as_smptett` | Major rewrite: | | | - Add NULL checks for `final` and `temp` malloc | | | - Track `buf_size` and use throughout | | | - Replace `strcpy/strcat` chains with `memcpy/snprintf` | | | - Use `snprintf` for style tags and color code formatting | ## Test plan - [x] Build succeeds without errors - [ ] Verify SMPTE-TT output format is unchanged for basic subtitles - [ ] Verify styled subtitles (italic, bold, underline) render correctly - [ ] Verify font color subtitles render correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:22:41 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2540