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

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

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1794
Author: @cfsmp3
Created: 12/12/2025
Status: Merged
Merged: 12/12/2025
Merged by: @cfsmp3

Base: masterHead: fix/dvb-subtitle-memory-safety


📝 Commits (2)

  • 877156c fix(matroska): add memory safety checks and fix memory leaks
  • d02736b fix(dvb_subtitle_decoder): add NULL checks after malloc calls

📊 Changes

2 files changed (+147 additions, -24 deletions)

View changed files

📝 src/lib_ccx/dvb_subtitle_decoder.c (+40 -3)
📝 src/lib_ccx/matroska.c (+107 -21)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/1794 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/12/2025 **Status:** ✅ Merged **Merged:** 12/12/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/dvb-subtitle-memory-safety` --- ### 📝 Commits (2) - [`877156c`](https://github.com/CCExtractor/ccextractor/commit/877156c59032510e1d0e71913f4207c326db3cc3) fix(matroska): add memory safety checks and fix memory leaks - [`d02736b`](https://github.com/CCExtractor/ccextractor/commit/d02736bf1aa7391aa4a6f1780fdcf6088658b369) fix(dvb_subtitle_decoder): add NULL checks after malloc calls ### 📊 Changes **2 files changed** (+147 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/dvb_subtitle_decoder.c` (+40 -3) 📝 `src/lib_ccx/matroska.c` (+107 -21) </details> ### 📄 Description ## 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#2528