[PR #1815] [MERGED] fix(memory): Add null checks for unchecked memory allocations #2556

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

📋 Pull Request Information

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

Base: masterHead: fix/unchecked-memory-allocations


📝 Commits (1)

  • 818c78e fix(memory): Add null checks for unchecked memory allocations

📊 Changes

10 files changed (+41 additions, -7 deletions)

View changed files

📝 src/lib_ccx/asf_functions.c (+4 -0)
📝 src/lib_ccx/ccx_decoders_608.c (+2 -0)
📝 src/lib_ccx/ccx_decoders_isdb.c (+5 -0)
📝 src/lib_ccx/ccx_decoders_xds.c (+4 -0)
📝 src/lib_ccx/ccx_dtvcc.c (+2 -2)
📝 src/lib_ccx/ccx_encoders_webvtt.c (+4 -0)
📝 src/lib_ccx/dvb_subtitle_decoder.c (+2 -2)
📝 src/lib_ccx/general_loop.c (+8 -1)
📝 src/lib_ccx/lib_ccx.c (+6 -2)
📝 src/lib_ccx/mp4.c (+4 -0)

📄 Description

Summary

  • Add proper null checks after malloc/calloc/realloc calls to prevent potential NULL pointer dereferences on out-of-memory conditions
  • Fix a variable shadowing bug in general_loop.c that caused a memory leak
  • Fix incorrect check ordering where null checks happened after pointer dereferences

Changes

File Issue Fixed
general_loop.c Add null checks for line and parsebuf; remove duplicate allocation that shadowed outer bytes variable (memory leak)
ccx_encoders_webvtt.c Add null check for color_events/font_events calloc
ccx_decoders_isdb.c Add null check for text->buf before dereference
dvb_subtitle_decoder.c Move null check before memset (was crashing on OOM before reaching check)
mp4.c Add null check for dec_sub->data before memcpy
ccx_decoders_608.c Add null check for decoder context allocation
ccx_decoders_xds.c Add null check for string buffer allocation
asf_functions.c Add null check after struct initialization containing malloc
ccx_dtvcc.c Move null check before dereferences (was checking after using pointer)
lib_ccx.c Fix memset-before-check ordering; add checks for pesheaderbuf and DVB context

Test plan

  • Build completes successfully
  • Run test suite to verify no regressions

🤖 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/1815 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/14/2025 **Status:** ✅ Merged **Merged:** 12/14/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/unchecked-memory-allocations` --- ### 📝 Commits (1) - [`818c78e`](https://github.com/CCExtractor/ccextractor/commit/818c78e8087073f6eeb619cd2c3de336d2274ce1) fix(memory): Add null checks for unchecked memory allocations ### 📊 Changes **10 files changed** (+41 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/lib_ccx/asf_functions.c` (+4 -0) 📝 `src/lib_ccx/ccx_decoders_608.c` (+2 -0) 📝 `src/lib_ccx/ccx_decoders_isdb.c` (+5 -0) 📝 `src/lib_ccx/ccx_decoders_xds.c` (+4 -0) 📝 `src/lib_ccx/ccx_dtvcc.c` (+2 -2) 📝 `src/lib_ccx/ccx_encoders_webvtt.c` (+4 -0) 📝 `src/lib_ccx/dvb_subtitle_decoder.c` (+2 -2) 📝 `src/lib_ccx/general_loop.c` (+8 -1) 📝 `src/lib_ccx/lib_ccx.c` (+6 -2) 📝 `src/lib_ccx/mp4.c` (+4 -0) </details> ### 📄 Description ## Summary - Add proper null checks after malloc/calloc/realloc calls to prevent potential NULL pointer dereferences on out-of-memory conditions - Fix a variable shadowing bug in `general_loop.c` that caused a memory leak - Fix incorrect check ordering where null checks happened after pointer dereferences ## Changes | File | Issue Fixed | |------|-------------| | `general_loop.c` | Add null checks for `line` and `parsebuf`; remove duplicate allocation that shadowed outer `bytes` variable (memory leak) | | `ccx_encoders_webvtt.c` | Add null check for `color_events`/`font_events` calloc | | `ccx_decoders_isdb.c` | Add null check for `text->buf` before dereference | | `dvb_subtitle_decoder.c` | Move null check before `memset` (was crashing on OOM before reaching check) | | `mp4.c` | Add null check for `dec_sub->data` before `memcpy` | | `ccx_decoders_608.c` | Add null check for decoder context allocation | | `ccx_decoders_xds.c` | Add null check for string buffer allocation | | `asf_functions.c` | Add null check after struct initialization containing malloc | | `ccx_dtvcc.c` | Move null check before dereferences (was checking *after* using pointer) | | `lib_ccx.c` | Fix memset-before-check ordering; add checks for `pesheaderbuf` and DVB context | ## Test plan - [x] Build completes successfully - [ ] Run test suite to verify no regressions 🤖 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:45 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2556