Skip to content

Conversation

@ABildstein
Copy link
Contributor

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

This PR improves the handling of ICC profiles, specifically:

  • fixes profile ID calculation
  • add check for the validity of a profile and use it in the jpeg decoders
  • change the ToByteArray method to use the underlying buffer instead of parsing and then writing the profile
  • make parsing of profile data more defensive to guard against corrupt data

That last point is not extensive and could need some more work. Currently only the tag table is checked for invalid values but it would make sense for many values to check them during parsing as well.
For example, often a number of array items or a position within the profile is read. I'm not sure how to best handle it yet and may need some medium changes and a separate PR.
Until the profiles are actually used for color management, it's not really relevant though. The issues that surfaced with corrupt profiles only occured because of the way ToByteArray was implemented.

This PR fixes #578, #559 and #562

@codecov
Copy link

codecov bot commented May 22, 2018

Codecov Report

Merging #588 into master will decrease coverage by 0.03%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #588      +/-   ##
==========================================
- Coverage    88.8%   88.77%   -0.04%     
==========================================
  Files         853      854       +1     
  Lines       36100    36168      +68     
  Branches     2607     2610       +3     
==========================================
+ Hits        32059    32108      +49     
- Misses       3267     3287      +20     
+ Partials      774      773       -1
Impacted Files Coverage Δ
...p/Formats/Jpeg/GolangPort/GolangJpegDecoderCore.cs 75.46% <0%> (-0.57%) ⬇️
.../MetaData/Profiles/ICC/DataReader/IccDataReader.cs 94.11% <100%> (ø) ⬆️
...arp.Tests/MetaData/Profiles/ICC/IccProfileTests.cs 100% <100%> (ø)
...mageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs 100% <100%> (ø) ⬆️
...arp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs 83.71% <50%> (-0.55%) ⬇️
src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs 91.93% <72.22%> (-8.07%) ⬇️
src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs 91.3% <88.46%> (-1.56%) ⬇️
...C/TagDataEntries/IccTextDescriptionTagDataEntry.cs 48.48% <0%> (-6.07%) ⬇️
...files/ICC/DataWriter/IccDataWriter.TagDataEntry.cs 77.14% <0%> (-1.43%) ⬇️
...rofiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs 48.27% <0%> (ø) ⬆️
... and 3 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 90272b4...df7fa40. Read the comment docs.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

THE KING OF ICC!!!

Looking good, just some minor changes to ensure we don't affect performance.

fileMarker = FindNextFileMarker(this.markerBuffer, this.InputStream);
}

if (this.MetaData.IccProfile?.CheckIsValid() == false)
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to AssignResolution and rename that to InitDerivedMetaDataProperties, The return above prevents us reading more than we need to when we are identifying images.

Copy link
Contributor Author

@ABildstein ABildstein May 23, 2018

Choose a reason for hiding this comment

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

I initially wanted to put it there, but it's only called from Decode and Identify and not in ParseStream. In the go port it's called at the end of the ParseStream method (and by extension in Decode and Identify).
Should we move AssignResolution there as well? I changed the return you mentioned to a break so things after the while loop will be executed.

Copy link
Member

Choose a reason for hiding this comment

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

Both Decode and Identify call ParseStream in both decoders. We want to return at that point in PdfJs decoder to avoid reading the entire SOS segment when we don’t need to. So using break slows us down.

I can move the method if you like? Save you the bother.

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 they do, but ParseStream is public so it can be called directly, that's the only reason I wanted to do it there.
Sorry about the return thing, I thought break behaves differently at that point. We could use a
goto to jump out of the while (it's evil, I know :P)

and no worries, it's a small change, I can do it.

Copy link
Member

Choose a reason for hiding this comment

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

👍 It's only public as we use it for tests. The class is internal so not available to consumers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok great, then there's no reason to change anything in that regard. Will push changes in a couple minutes.


this.InitDerivedMetaDataProperties();

if (this.MetaData.IccProfile?.CheckIsValid() == false)
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to InitDerivedMetaDataProperties

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.

System.ArgumentOutOfRangeException for Parameter name: start loading a jpg

2 participants