-
Notifications
You must be signed in to change notification settings - Fork 426
Pointer Offset Overflow in onig #2571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
For all of your advisories, please ask the maintainer whether they would be okay with an advisory being published. |
|
Are you actually going to fix it upstream? How would this be triggered and what would the result be? |
|
YES, a very large usize value will overflow when converted to isize; Rust permits this conversion without triggering a panic. However, when such a value is later used with unsafe operations like ptr::offset, the resulting address calculation overflow is detected. |
|
Did you write code that can trigger this? Here's the code: /// Returns the start and end positions of the Nth capture group.
///
/// Returns `None` if `pos` is not a valid capture group or if the
/// capture group did not match anything. The positions returned
/// are always byte indices with respect to the original string
/// matched.
pub fn pos(&self, pos: usize) -> Option<(usize, usize)> {
if pos >= self.len() {
return None;
}
let pos = pos as isize;
let (beg, end) = unsafe { (*self.raw.beg.offset(pos), *self.raw.end.offset(pos)) };
if beg != onig_sys::ONIG_REGION_NOTPOS {
Some((beg as usize, end as usize))
} else {
None
}
}As such, |
|
Thank you for your response. While your logic holds true for standard use cases, the issue I've identified arises from an integer overflow/truncation during the FFI call in Here is trigger code and the follow is step-by-step breakdown of how the safety check is bypassed: let _local0 = onig::Region::with_capacity(_param0);
let result = onig::Region::pos(&_local0, _param1);
Here is the output after executing the code: Same root cause, but resulting in a different bug and security impact. Please see here. I can provide a PoC if you're interested. |

A pointer offset overflow vulnerability has been discovered in the
Region::posmethod of the rust-onig library. The method performs an unchecked conversion fromusizetoisize, which can lead to address calculation overflow in the subsequentptr::offsetoperation.Crash Information:
Error Type: unsafe precondition(s) violated: ptr::offset requires the address calculation to not overflow
Location: region.rs in Region::pos
Root Cause: Conversion of usize values greater than isize::MAX to isize causes integer overflow
The issue is here.