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

Allocate clean buffer in AnalyzeEntropy #1873

Merged
merged 2 commits into from
Dec 4, 2021
Merged

Allocate clean buffer in AnalyzeEntropy #1873

merged 2 commits into from
Dec 4, 2021

Conversation

brianpopow
Copy link
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR fixes a bug in AnalyzeEntropy which did not allocate a clean buffer from the memory allocator, resulting in possible unpredictable results.

Closes #1872

@codecov
Copy link

codecov bot commented Dec 4, 2021

Codecov Report

Merging #1873 (3780ca7) into master (8fbc68c) will decrease coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1873   +/-   ##
======================================
- Coverage      87%     87%   -1%     
======================================
  Files         935     935           
  Lines       48939   48939           
  Branches     6086    6086           
======================================
- Hits        42872   42814   -58     
- Misses       5059    5115   +56     
- Partials     1008    1010    +2     
Flag Coverage Δ
unittests 87% <100%> (-1%) ⬇️

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

Impacted Files Coverage Δ
...rc/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs 97% <100%> (-1%) ⬇️
...mageSharp/Formats/Webp/Lossless/NearLosslessEnc.cs 9% <0%> (-80%) ⬇️
...ageSharp/Formats/Webp/Lossless/PredictorEncoder.cs 94% <0%> (-4%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fbc68c...3780ca7. Read the comment docs.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

Any chance we can somehow regression test this? (Eg. check resulting stream size in some of the encoder tests?)

@brianpopow
Copy link
Collaborator Author

Any chance we can somehow regression test this? (Eg. check resulting stream size in some of the encoder tests?)

I have added a test to check for the expected file size, but I am not sure if that will trigger the actual issue. The issue #1872 will only happen, if the allocator will allocate unclean buffers, which i believe will not be the case when i create a new instance of WebpEncoder

using var memoryStream = new MemoryStream();
image.Save(memoryStream, encoder);

Assert.Equal(memoryStream.Length, expectedBytes);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need strict equality? Doesn't the spec allow some space for the implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No the spec is not that strict. The analyses step could have choosen different transformation, e.g. here the analyses step has choosen to use the following features PREDICTION CROSS-COLOR-TRANSFORM SUBTRACT-GREEN. If one of those transformations would not been applied, the image would be still valid, but a bit larger.

Nonetheless i think we should try to aim to be as close to the reference implementation as possible and this is what libwebp would have encoded to.

Copy link
Member

Choose a reason for hiding this comment

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

Ok then, we can relax this restriction later if it will become necessary for some reason in the future.

@brianpopow brianpopow merged commit 952af37 into master Dec 4, 2021
@brianpopow brianpopow deleted the bp/fix1872 branch December 4, 2021 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lossless Webp encoded files does not match reference implementation
2 participants