[PR #1794] fix(dvb_subtitle_decoder): add NULL checks after malloc calls #2531

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

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

State: closed
Merged: Yes


Summary

This PR adds missing NULL checks for 9 malloc() calls in the DVB subtitle decoder (src/lib_ccx/dvb_subtitle_decoder.c) that could cause crashes or undefined behavior if memory allocation fails.

Changes

All checks use fatal(EXIT_NOT_ENOUGH_MEMORY, ...) to terminate gracefully with an appropriate error message, consistent with the approach used in matroska.c and other parts of the codebase.

Affected Functions and Allocations

Function Allocation Line
dvbsub_init_decoder() DVBSubContext 424
dvbsub_parse_clut_segment() DVBSubCLUT 1146
dvbsub_parse_region_segment() DVBSubRegion 1254
dvbsub_parse_region_segment() region->pbuf 1287
dvbsub_parse_region_segment() DVBSubObject 1332
dvbsub_parse_region_segment() DVBSubObjectDisplay 1347
dvbsub_parse_page_segment() DVBSubRegionDisplay 1438
write_dvb_sub() cc_bitmap (rect) 1553
write_dvb_sub() rect->data1 1636
write_dvb_sub() rect->data0 1656
dvbsub_handle_display_segment() private_data 1768

Additional Fix

This also fixes a potential memory leak in write_dvb_sub() where rect and rect->data1 would be leaked if the rect->data0 allocation failed (previously returned -1 without cleanup, now terminates via fatal()).

Context

This is part of a systematic effort to improve memory safety across the CCExtractor codebase. The DVB subtitle decoder was identified as having 28 memory-related function calls, making it a high-priority target for review.

Test plan

  • Code compiles without errors
  • Run with DVB subtitle streams to verify normal operation
  • Memory allocation failures will now produce clear error messages instead of crashes

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1794 **State:** closed **Merged:** Yes --- ## Summary This PR adds missing NULL checks for **9 malloc() calls** in the DVB subtitle decoder (`src/lib_ccx/dvb_subtitle_decoder.c`) that could cause crashes or undefined behavior if memory allocation fails. ### Changes All checks use `fatal(EXIT_NOT_ENOUGH_MEMORY, ...)` to terminate gracefully with an appropriate error message, consistent with the approach used in `matroska.c` and other parts of the codebase. ### Affected Functions and Allocations | Function | Allocation | Line | |----------|------------|------| | `dvbsub_init_decoder()` | `DVBSubContext` | 424 | | `dvbsub_parse_clut_segment()` | `DVBSubCLUT` | 1146 | | `dvbsub_parse_region_segment()` | `DVBSubRegion` | 1254 | | `dvbsub_parse_region_segment()` | `region->pbuf` | 1287 | | `dvbsub_parse_region_segment()` | `DVBSubObject` | 1332 | | `dvbsub_parse_region_segment()` | `DVBSubObjectDisplay` | 1347 | | `dvbsub_parse_page_segment()` | `DVBSubRegionDisplay` | 1438 | | `write_dvb_sub()` | `cc_bitmap` (rect) | 1553 | | `write_dvb_sub()` | `rect->data1` | 1636 | | `write_dvb_sub()` | `rect->data0` | 1656 | | `dvbsub_handle_display_segment()` | `private_data` | 1768 | ### Additional Fix This also fixes a **potential memory leak** in `write_dvb_sub()` where `rect` and `rect->data1` would be leaked if the `rect->data0` allocation failed (previously returned -1 without cleanup, now terminates via `fatal()`). ### Context This is part of a systematic effort to improve memory safety across the CCExtractor codebase. The DVB subtitle decoder was identified as having 28 memory-related function calls, making it a high-priority target for review. ## Test plan - [x] Code compiles without errors - [ ] Run with DVB subtitle streams to verify normal operation - [ ] Memory allocation failures will now produce clear error messages instead of crashes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:22:37 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2531