[PR #1707] fix: XDS segmentation faults #2428

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

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

State: closed
Merged: Yes


In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

The regression tests under the XDS category have been failing on Windows due to segmentation faults for a while now. The cause for these errors stem from a small mistake that was made when the CEA-708 decoder functions were ported to Rust.

In specific, here is the offending line:

// Add symbol to window
window.rows[window.pen_row as usize] = Box::into_raw(Box::new(sym));

To contrast, here is the equivalent C section:

window->rows[window->pen_row][window->pen_column] = symbol;

window.rows has the following definition:

dtvcc_symbol *rows[15];
rows[i] = (dtvcc_symbol *)malloc(64 * sizeof(dtvcc_symbol));

As we can see, it is an array of pointers where each pointer points to a heap allocated row of dtvcc_symbols. In rust, this structure is incorrectly assumed to be an array of dtvcc_symbols. I've fixed this by using pointer arithmetic in rust to do the proper operation:

unsafe {
    let ptr: *mut dtvcc_symbol =
        window.rows[window.pen_row as usize].add(window.pen_column as usize);
    *ptr = sym;
}

The unit tests which directly utilize this operation were also leaking memory due to this, and thus I've made helper functions to properly handle those as well.

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/1707 **State:** closed **Merged:** Yes --- <!-- Please prefix your pull request with one of the following: **[FEATURE]** **[FIX]** **[IMPROVEMENT]**. --> **In raising this pull request, I confirm the following (please check boxes):** - [x] I have read and understood the [contributors guide](https://github.com/CCExtractor/ccextractor/blob/master/.github/CONTRIBUTING.md). - [x] I have checked that another pull request for this purpose does not exist. - [x] I have considered, and confirmed that this submission will be valuable to others. - [x] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. - [x] I give this submission freely, and claim no ownership to its content. - [x] **I have mentioned this change in the [changelog](https://github.com/CCExtractor/ccextractor/blob/master/docs/CHANGES.TXT).** **My familiarity with the project is as follows (check one):** - [ ] I have never used CCExtractor. - [ ] I have used CCExtractor just a couple of times. - [ ] I absolutely love CCExtractor, but have not contributed previously. - [x] I am an active contributor to CCExtractor. --- The regression tests under the XDS category have been failing on Windows due to segmentation faults for a while now. The cause for these errors stem from a small mistake that was made when the CEA-708 decoder functions were ported to Rust. In specific, here is the offending [line](https://github.com/hrideshmg/ccextractor/blob/54dfce4c89245f71b4ffc71e099e6298550a1cd5/src/rust/src/decoder/service_decoder.rs#L1139): ```Rust // Add symbol to window window.rows[window.pen_row as usize] = Box::into_raw(Box::new(sym)); ``` To contrast, here is the equivalent C [section](https://github.com/hrideshmg/ccextractor/blob/54dfce4c89245f71b4ffc71e099e6298550a1cd5/src/lib_ccx/ccx_decoders_708.c#L799): ```C window->rows[window->pen_row][window->pen_column] = symbol; ``` `window.rows` has the following definition: ```C dtvcc_symbol *rows[15]; rows[i] = (dtvcc_symbol *)malloc(64 * sizeof(dtvcc_symbol)); ``` As we can see, it is an array of pointers where each pointer points to a heap allocated row of `dtvcc_symbols`. In rust, this structure is incorrectly assumed to be an array of `dtvcc_symbols`. I've fixed this by using pointer arithmetic in rust to do the proper operation: ```Rust unsafe { let ptr: *mut dtvcc_symbol = window.rows[window.pen_row as usize].add(window.pen_column as usize); *ptr = sym; } ``` The unit tests which directly utilize this operation were also leaking memory due to this, and thus I've made helper functions to properly handle those as well.
claunia added the pull-request label 2026-01-29 17:22:05 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2428