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

Prevent zigzag overflow. Fix #922 #924

Merged
merged 3 commits into from
Jun 4, 2019
Merged

Prevent zigzag overflow. Fix #922 #924

merged 3 commits into from
Jun 4, 2019

Conversation

JimBobSquarePants
Copy link
Member

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 matches 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

Prevents potential overflow from corrupt jpegs. This is how libjpeg handles it.

@codecov
Copy link

codecov bot commented Jun 4, 2019

Codecov Report

Merging #924 into master will decrease coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #924      +/-   ##
==========================================
- Coverage   89.26%   89.14%   -0.12%     
==========================================
  Files        1076     1077       +1     
  Lines       47209    47218       +9     
  Branches     3315     3319       +4     
==========================================
- Hits        42140    42093      -47     
- Misses       4366     4371       +5     
- Partials      703      754      +51
Impacted Files Coverage Δ
src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs 100% <100%> (ø) ⬆️
tests/ImageSharp.Tests/Formats/Jpg/ZigZagTests.cs 100% <100%> (ø)
...xelFormats/PixelOperations{TPixel}.PixelBenders.cs 89.9% <0%> (-10.1%) ⬇️
...olorSpaces/Conversion/ColorSpaceConverter.Adapt.cs 60% <0%> (-8.58%) ⬇️
...Processing/Processors/Transforms/TransformUtils.cs 87.64% <0%> (-6.75%) ⬇️
src/ImageSharp/Primitives/ValueSize.cs 78.94% <0%> (-5.27%) ⬇️
src/ImageSharp/Common/Helpers/ImageMaths.cs 81.81% <0%> (-5.2%) ⬇️
....Tests/TestUtilities/Tests/TestEnvironmentTests.cs 63.63% <0%> (-4.55%) ⬇️
...p/Processing/Processors/Dithering/ErrorDiffuser.cs 93.75% <0%> (-3.13%) ⬇️
...ormats/Jpeg/Components/Decoder/QualityEvaluator.cs 94.04% <0%> (-2.39%) ⬇️
... and 21 more

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 47852eb...dcbcf3c. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 4, 2019

Codecov Report

Merging #924 into master will increase coverage by <.01%.
The diff coverage is 93.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #924      +/-   ##
==========================================
+ Coverage   89.26%   89.26%   +<.01%     
==========================================
  Files        1076     1077       +1     
  Lines       47209    47230      +21     
  Branches     3315     3320       +5     
==========================================
+ Hits        42140    42159      +19     
- Misses       4366     4367       +1     
- Partials      703      704       +1
Impacted Files Coverage Δ
tests/ImageSharp.Tests/TestImages.cs 100% <ø> (ø) ⬆️
src/ImageSharp/Formats/Jpeg/Components/ZigZag.cs 100% <100%> (ø) ⬆️
...Sharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs 100% <100%> (ø) ⬆️
tests/ImageSharp.Tests/Formats/Jpg/ZigZagTests.cs 100% <100%> (ø)
...rmats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs 100% <100%> (ø) ⬆️
...mats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs 95.26% <60%> (-0.56%) ⬇️

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 47852eb...84256b6. 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.

Although #922 is not being reproducible with the runtimes currently covered by CI, and we have unit test in this PR, I strongly recommend to introduce an "integration" test, based on an image referenced in that issue. I asked whether it's reproducible with a smaller one.

Image-based regression tests are less prone to large-scale refactors, and an extensive set of images is a robust, implementation-agnostic specification for a modern production-quality decoder. (Especially if they come with issue references serving as explanatory docs.)

We've gotta collect 'em all!

@@ -68,7 +75,7 @@ public static ZigZag CreateUnzigTable()
{
ZigZag result = default;
byte* unzigPtr = result.Data;
Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, 64);
Marshal.Copy(Unzig, 0, (IntPtr)unzigPtr, 64 + 16);
Copy link
Member

Choose a reason for hiding this comment

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

Might make sense to define a constant for 64+16 or use Unzig.Length.

@JimBobSquarePants
Copy link
Member Author

I wasn’t sure about adding the image as it only exposes the issue and didn’t, to me seem important since we can test without inflating the project size.

We do render it differently to libjpeg though (I don’t know why) so maybe we should add it yeah.

@JimBobSquarePants
Copy link
Member Author

@antonfirsov I've added the image but commented it out of the decoder tests. We don't produce the same output as libjpeg and I don't want to spend the time attempting to discover why for a corrupted image.

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.

Cool, I can do the rest, in another PR.

I think we can address most repo size-related issues by implementing #868 and switching to Azure Pipelines.

@antonfirsov antonfirsov merged commit 8107587 into master Jun 4, 2019
@JimBobSquarePants JimBobSquarePants deleted the js/zigzag-overflow branch September 3, 2019 11:10
antonfirsov added a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
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.

2 participants