Fix null pointer handling in edit_distance#2263
Open
THE-Amrit-mahto-05 wants to merge 2 commits intoCCExtractor:masterfrom
Open
Fix null pointer handling in edit_distance#2263THE-Amrit-mahto-05 wants to merge 2 commits intoCCExtractor:masterfrom
THE-Amrit-mahto-05 wants to merge 2 commits intoCCExtractor:masterfrom
Conversation
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 ad4886e...:
Your PR breaks these cases:
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:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
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 ad4886e...:
Your PR breaks these cases:
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:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Problem
The function
edit_distanceis part of the Rust FFI layer and is exposed to C code. In C usage, NULL pointers are valid inputs, but the current implementation does not safely handle them.Issue
word1orword2leads to unsafe dereference viaCStr::from_ptrProof
The issue can be reproduced by calling the function with NULL pointers from the FFI boundary.
Steps to reproduce
edit_distance(word1 = NULL, word2 = "abc", len1 = 0, len2 = 3)edit_distance(word1 = "abc", word2 = NULL, len1 = 3, len2 = 0)Expected behavior
The function should safely handle NULL inputs and return:
Actual behavior (before fix)
Unsafe pointer dereference occurs when converting NULL pointers using CStr::from_ptr, leading to undefined behavior or crash.
Fix
CStr::from_ptrusageIn the C FFI boundary, NULL pointers are treated as empty inputs when passed to
edit_distance.When one input is NULL, the function returns the length of the other string, treating it as a full deletion/insertion cost.
This behavior is consistent with the existing interpretation of edit distance and ensures safe handling without undefined behavior.
Testing
cargo test --features hardsubx_ocredit_distanceImpact
This change improves memory safety and prevents undefined behavior in Rust bindings exposed to C via FFI.