Skip to content

Conversation

@vatsalkeshav
Copy link
Contributor

@vatsalkeshav vatsalkeshav commented Mar 16, 2025

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.

This PR migrates /src/lib_ccx/ccx_decoders_isdb.c to rust.
These changes have been made-

  1. Pure rust equivalent functions in /src/rust/lib_ccxr/src/decoder_isdb/functions_isdb.rs, functions_common.rs
  2. Required datatypes in /src/rust/lib_ccxr/src/decoder_isdb/structs_xds.rs, structs_isdb.rs , structs_ccdecode.rs(thanks @steel-bucket)
  3. Exit codes etc in /src/rust/lib_ccxr/src/decoder_isdb/exit_codes.rs
  4. C-compatible rust functions/exports in src/rust/src/libccxr_exports/isdb_exports.rs
  5. Declaration and use of written rust functions in /src/lib_ccx/ccx_decoders_isdb.c

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 9e2a594...:

Report Name Tests Passed
Broken 0/13
CEA-708 0/14
DVB 0/7
DVD 0/3
DVR-MS 0/2
General 0/27
Hauppage 0/3
MP4 0/3
NoCC 0/10
Options 0/86
Teletext 0/21
WTV 0/13
XDS 0/34

All tests passing on the master branch were passed completely.

NOTE: The following tests have been failing on the master branch as well as the PR:


Check the result page for more info.

@vatsalkeshav vatsalkeshav changed the title [FEAT] added isdbs module in lib_ccxr [WIP] added isdbs module in lib_ccxr Mar 21, 2025
@vatsalkeshav vatsalkeshav marked this pull request as draft March 23, 2025 03:43
@vatsalkeshav vatsalkeshav reopened this Mar 23, 2025
@vatsalkeshav vatsalkeshav marked this pull request as ready for review March 23, 2025 07:04
@vatsalkeshav vatsalkeshav marked this pull request as draft March 23, 2025 13:09
@vatsalkeshav vatsalkeshav marked this pull request as ready for review March 23, 2025 13:34
@vatsalkeshav vatsalkeshav marked this pull request as draft March 23, 2025 13:36
@vatsalkeshav vatsalkeshav changed the title [WIP] added isdbs module in lib_ccxr [feat] added isdbs module in lib_ccxr Mar 23, 2025
@vatsalkeshav vatsalkeshav marked this pull request as ready for review March 23, 2025 13:59
@vatsalkeshav vatsalkeshav changed the title [feat] added isdbs module in lib_ccxr [FEAT] Add decoder_isdb module in lib_ccxr Mar 28, 2025
@vatsalkeshav vatsalkeshav changed the title [FEAT] Add decoder_isdb module in lib_ccxr [FEAT] Add module decoder_isdb module in lib_ccxr Mar 28, 2025
@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit b62027a...:

Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 79/86
Teletext 21/21
WTV 13/13
XDS 34/34

All tests passing on the master branch were passed completely.

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:


Check the result page for more info.

@vatsalkeshav vatsalkeshav changed the title [FEAT] Add module decoder_isdb module in lib_ccxr [FEAT] Add module decoder_isdb in lib_ccxr Apr 12, 2025
@vatsalkeshav vatsalkeshav changed the title [FEAT] Add module decoder_isdb in lib_ccxr [FEAT] WIP module decoder_isdb in lib_ccxr Apr 21, 2025
Copy link
Contributor

@cfsmp3 cfsmp3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on migrating the ISDB decoder to Rust! The overall structure looks good and the build succeeds.

However, I found a critical memory safety bug that needs to be fixed:

Use-after-free in reserve_buf() (functions_isdb.rs:59-80):

let mut new_buf = Vec::with_capacity(blen);
new_buf.extend_from_slice(unsafe { std::slice::from_raw_parts(text.buf, text.used) });

text.buf = new_buf.as_mut_ptr();  // Store pointer to Vec's buffer
text.len = blen;
// BUG: new_buf is dropped here, freeing the memory!
// text.buf now points to freed memory - use-after-free!

The new_buf Vec goes out of scope and is deallocated, but text.buf still points to the freed memory. You correctly used std::mem::forget(buf) in allocate_text_node() to prevent this - the same pattern is needed here:

text.buf = new_buf.as_mut_ptr();
text.len = blen;
std::mem::forget(new_buf);  // Add this line to prevent deallocation!

Additionally, the old buffer (text.buf) should be freed before being replaced to avoid a memory leak. Something like:

// Free old buffer if it exists
if !text.buf.is_null() && text.len > 0 {
    unsafe { drop(Vec::from_raw_parts(text.buf, text.used, text.len)); }
}
// Then allocate new buffer...

This bug likely explains why the CI - linux sample platform tests are timing out - use-after-free can cause infinite loops, crashes, or memory corruption.

Other notes:

  1. PR has merge conflicts that need to be resolved
  2. Remove "WIP" from title when ready for final review
  3. Consider adding unit tests for the Rust implementation to catch issues like this

Once the memory bug is fixed and rebased, this should be ready for more detailed functional testing.

@vatsalkeshav
Copy link
Contributor Author

Sure

I'll push some local changes after working on #1679
which will address these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants