-
Notifications
You must be signed in to change notification settings - Fork 808
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
unsigned integer underflow #1696
Comments
Seeing the same issue. Also, I am not sure if "user error" is the right connotation here. The trait seems pretty broken if you ask me, as it appears to make the assumption that E.g., this program panics to due over/underflow: use nom::error::ErrorKind::Tag;
use nom::error::VerboseErrorKind::Nom;
use nom::error::convert_error;
use nom::error::VerboseError;
fn main() {
let input = [31, 139, 8, 8, 85, 135, 48, 102, 2, 255, 108, 105, 98];
let err = VerboseError {
errors: vec![(String::from_utf8_lossy(&input), Nom(Tag))],
};
let _x = convert_error(String::from_utf8_lossy(&input), err);
} the problem isn't really obvious at all. And in a general setting, neither may the fix be (on the user's end). |
We have gotten reports of a crash caused by numeric overflow when attempting to parse a Breakpad file. The reason lies in the error conversion functionality that nom provides. Specifically, the nom::error::convert_error() function expects errors with a context that derefs to an str slice. In order to fulfill that contract we convert everything to Cow<str>. However, the function also implicitly assumes that substrings belong to the same input slice. That is not the case, and cannot be easily fixed, because there is no sane way of "relocating" arbitrary byte slice after a lossy string conversion. The requirement of derefing into a str while *also* mapping to byte slices and are assumed to be subslices of each other just seems plain broken. This change imports a copy of the convert_error() function and fixes up the broken bits. The upstream issue touching on this problem is: rust-bakery/nom#1696 Signed-off-by: Daniel Müller <[email protected]>
@mxyns @danielocfb as you saw, |
Yes, that is the reason. The function assumes something that derefs into Btw., I accidentally commented what is not the most fitting issue, I think #1619 actually covers this very problem already. |
Hello,
While using nom I encountered an issue with this impl of Offset for [u8]
nom/src/traits.rs
Lines 599 to 606 in 8c68e22
The return value underflows when the first span is after the second in memory. This means the user always has to think about whether to use
first.offset(second)
orsecond.offset(first)
:To me, an offset means it may be negative but maybe changing the return type of the offset method to
isize
may be problematic elsewhere, I don't know a lot about the internals of nom.Maybe just doing an absolute value of the result could be enough? or let Offset have a signed version of the offset method?
The text was updated successfully, but these errors were encountered: