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

Fixed crash while mgf parsing #12

Merged
merged 4 commits into from
Oct 16, 2024
Merged

Conversation

douweschulte
Copy link
Contributor

@douweschulte douweschulte commented Oct 16, 2024

I found a rare crash while reading MGF files. By the way the function Option::take does exactly what you are doing with mem::swap while being more main stream in other Rust code. I saw this same pattern at some other places in the code base so changing those might be warranted.

@douweschulte douweschulte marked this pull request as ready for review October 16, 2024 11:35
@douweschulte
Copy link
Contributor Author

douweschulte commented Oct 16, 2024

Root cause description

fixes where applied in the reverse order from this description

I figured out that the root cause is that in a recent update mzdata started parsing CHARGE=XX in mgf, as I used 2+ instead of +2 for the charge field the parsing broke down. After breaking down the parser had its state self.state as error and work as false. Because the error state was never checked the main parsing loop finished and an unfinished spectrum was returned and any further reading of the spectra will fail.

Additionally the error.unwrap() crashed in this case which in some way lead to a panic in a panic which fully crashed the annotator.

Description of changes

  • Fixed crash when no error is saved in self.error
  • Fixed MGF parser ignoring errors encountered during handling of the MGF line
  • Updated MGF CHARGE parser to handle 2+
  • Refactored some code to be more in line with Clippys suggestions and Rust idioms

@douweschulte douweschulte changed the title Fixed rare crash while mgf parsing Fixed crash while mgf parsing Oct 16, 2024
@mobiusklein
Copy link
Owner

Thank you for fixing this. Please let me know when you're ready for this to be merged.

@douweschulte
Copy link
Contributor Author

I am ready for merging.

@mobiusklein mobiusklein merged commit 93c19a9 into mobiusklein:main Oct 16, 2024
2 checks passed
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 this pull request may close these issues.

2 participants