Skip to content
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

Parsing replay files can panic in debug mode. #19

Closed
Kered13 opened this issue Aug 20, 2022 · 2 comments · Fixed by #41
Closed

Parsing replay files can panic in debug mode. #19

Kered13 opened this issue Aug 20, 2022 · 2 comments · Fixed by #41

Comments

@Kered13
Copy link

Kered13 commented Aug 20, 2022

Line 829 in serde/de.rs can overflow and panic if the replay file is corrupted. The function should return a ParseError instead. I have had this happen on actual replay files that were generated by Slippi, so it doesn't even require random garbage to trigger (I'm not sure why they are corrupted, but I have dozens of such files from playing thousands of games).

There may be other possible places that could panic, but I have not checked the entire parsing code. Any unchecked arithmetic is a potential overflow though. On these particular files it only panics if I am skipping frames though.

Example file attached. Note however that I'm not asking why the file doesn't parse, I know it's corrupt. I'm just saying that the parsing functions should not panic.

corrupt.zip

@hohav
Copy link
Owner

hohav commented Aug 21, 2022

Thanks for the report. You're right, we shouldn't panic on corrupt files. I should probably implement some basic fuzzing after fixing the obvious issues.

@NickCondron
Copy link
Contributor

NickCondron commented Dec 23, 2022

Seems like this happens when the raw_len field of the replay is 0. Subtracting bytes_read from 0 causes this panic. raw_len is supposed to be set to 0 for in-progress replay files, but something is failing preventing slippi from updating the 0 to a correct length.

The replay is corrupted, but through the lens of the Read trait, it may be impossible to distinguish between a corrupt replay with raw_len equal to 0 and a normal in-progress replay. I guess we will eventually encounter EOF when parsing a corrupted replay whereas an in-progress replay will simply block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants