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

Fails on empty comments without 4 -" #618

Merged
merged 1 commit into from
Jun 28, 2023
Merged

Fails on empty comments without 4 -" #618

merged 1 commit into from
Jun 28, 2023

Conversation

Tpt
Copy link
Contributor

@Tpt Tpt commented Jun 25, 2023

The parser was crashing because of bad slice bounds

Closes #604

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2023

Codecov Report

Merging #618 (2cf962a) into master (60249ae) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master     #618      +/-   ##
==========================================
- Coverage   64.67%   64.66%   -0.02%     
==========================================
  Files          36       36              
  Lines       16998    16998              
==========================================
- Hits        10994    10991       -3     
- Misses       6004     6007       +3     
Flag Coverage Δ
unittests 64.66% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/reader/buffered_reader.rs 85.51% <100.00%> (ø)

... and 2 files with indirect coverage changes

Copy link
Collaborator

@Mingun Mingun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that approach is good, but we need more bullet-proof tests that will actually test that we take this code path (by checking actual events).

tests/fuzzing.rs Outdated Show resolved Hide resolved
src/reader/parser.rs Outdated Show resolved Hide resolved
@Mingun
Copy link
Collaborator

Mingun commented Jun 26, 2023

Actually, fix of this issue not so simple. <!-->--> is a valid XML (see #258 (comment))

@Tpt
Copy link
Contributor Author

Tpt commented Jun 27, 2023

Actually, fix of this issue not so simple. --> is a valid XML (see #258 (comment))

Indeed. Thank you for spotting this! I have found a cleaner way to fix the bug that behaves properly in this case.

Copy link
Collaborator

@Mingun Mingun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good, thanks! I left several comments

tests/issues.rs Outdated Show resolved Hide resolved
tests/issues.rs Outdated Show resolved Hide resolved
src/reader/parser.rs Outdated Show resolved Hide resolved
tests/issues.rs Outdated Show resolved Hide resolved
@Tpt
Copy link
Contributor Author

Tpt commented Jun 27, 2023

Thank you! I have updated the tests following your review!

Copy link
Collaborator

@Mingun Mingun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but I'd like to postpone merging until I'll get idea how it is working

@@ -117,7 +117,7 @@ macro_rules! impl_buffered_source {
// somewhere sane rather than at the EOF
Ok(n) if n.is_empty() => return Err(bang_type.to_err()),
Ok(available) => {
if let Some((consumed, used)) = bang_type.parse(buf, available) {
if let Some((consumed, used)) = bang_type.parse(&buf[start..], available) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand, how the fix worked. I feel it will be worth if this line will have a comment, why we need to take bytes only from start. Maybe with an examples of buf content for better understanding. If you known, what happens here, could you add such a comment? If not, I'll investigate that myself. Because tests are passed I assume that the fix is correct, but I want to know why it is correct

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, I understood. We should parse only newly read data from the buf. This is correct, because we in the function that parses the whole comment, so any data that exists in the buffer before is not relevant here and should be skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. I have added the comment. Not doing so was making some checks like the one on this line to be incorrect.

@Mingun
Copy link
Collaborator

Mingun commented Jun 28, 2023

Thanks! I slightly changed tests to more precisely test what an error we returns and changed Changelog description to be less technically specific and more user specific

@Mingun Mingun merged commit aca1f79 into tafia:master Jun 28, 2023
6 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.

Panic when parsing invalid comments <!-->
3 participants