-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
fix(unreal): Allow to parse with limit [INGEST-565] #447
Conversation
c074da2
to
188aa6f
Compare
symbolic-unreal/src/container.rs
Outdated
return Err(Unreal4ErrorKind::Empty.into()); | ||
} | ||
|
||
let mut decompressed = Vec::new(); | ||
std::io::copy(&mut ZlibDecoder::new(bytes), &mut decompressed) | ||
ZlibDecoder::new(slice) | ||
.take(limit as u64 + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alertnative to the +1 hack, I can offer this:
let mut decompressed = Vec::new();
let decoder = &mut ZlibDecoder::new(slice);
decoder
.take(limit as u64)
.read_to_end(&mut decompressed)
.map_err(|e| Unreal4Error::new(Unreal4ErrorKind::BadCompression, e))?;
if !matches!(decoder.read(&mut [0; 1]), Ok(0)) {
return Err(Unreal4ErrorKind::TooLarge.into());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that might be a good alternative, yes, as it makes the limit really explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the current code prevent you from using u64::MAX
as the limit? Not that one byte more or less is likely to make a difference, but still, I think it's kind of surprising behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that's also why the default limit is set to usize::MAX - 1
in the parse
method above.
Going to update this with code from the comment and add a test, then.
symbolic-unreal/src/container.rs
Outdated
return Err(Unreal4ErrorKind::Empty.into()); | ||
} | ||
|
||
let mut decompressed = Vec::new(); | ||
std::io::copy(&mut ZlibDecoder::new(bytes), &mut decompressed) | ||
ZlibDecoder::new(slice) | ||
.take(limit as u64 + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that might be a good alternative, yes, as it makes the limit really explicit.
ec08bd9
to
8212a21
Compare
To avoid unbounded allocation on bad input data, this PR introduces a new API
Unreal4Crash::parse_with_limit
that allows specifying a maximum allocationsize.