[PR #1878] [FIX] Handle NULL bitmap gracefully in OCR instead of crashing (#1010) #2661

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

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

State: closed
Merged: Yes


Summary

  • When processing DVB subtitles from live streams or corrupted files, bitmap clipping can fail
  • Previously this caused a fatal crash: "Failed to perform OCR - Failed to get text"
  • Now gracefully skips problematic frames instead of crashing

Root Cause

The code path was:

  1. pixClipRectangle fails → "box outside rectangle" error
  2. pixConvertRGBToGray receives NULL → "pixs not defined" error
  3. cpix_gs is NULL, but code continues to line 415
  4. TessBaseAPIGetUTF8Text returns NULL (no image was set)
  5. fatal() is called → crash

Fix

  • Handle cpix_gs == NULL by cleaning up and returning NULL (skip bitmap)
  • Change TessBaseAPIGetUTF8Text NULL case from fatal error to graceful skip
  • Both cases properly clean up allocated resources before returning

Testing

This fix allows CCExtractor to continue processing even when individual subtitle frames are corrupted, which is critical for live streams where packet loss can occur.

Fixes #1010

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1878 **State:** closed **Merged:** Yes --- ## Summary - When processing DVB subtitles from live streams or corrupted files, bitmap clipping can fail - Previously this caused a fatal crash: "Failed to perform OCR - Failed to get text" - Now gracefully skips problematic frames instead of crashing ## Root Cause The code path was: 1. `pixClipRectangle` fails → "box outside rectangle" error 2. `pixConvertRGBToGray` receives NULL → "pixs not defined" error 3. `cpix_gs` is NULL, but code continues to line 415 4. `TessBaseAPIGetUTF8Text` returns NULL (no image was set) 5. `fatal()` is called → crash ## Fix - Handle `cpix_gs == NULL` by cleaning up and returning NULL (skip bitmap) - Change `TessBaseAPIGetUTF8Text` NULL case from fatal error to graceful skip - Both cases properly clean up allocated resources before returning ## Testing This fix allows CCExtractor to continue processing even when individual subtitle frames are corrupted, which is critical for live streams where packet loss can occur. Fixes #1010 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:23:18 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2661