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

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

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

State: closed
Merged: Yes


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

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1815 **State:** closed **Merged:** Yes --- ## 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)
claunia added the pull-request label 2026-01-29 17:22:46 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2559