imgcodecs: png: add log if first chunk is not IHDR#27297
Merged
asmorkalov merged 2 commits intoopencv:4.xfrom May 12, 2025
Merged
imgcodecs: png: add log if first chunk is not IHDR#27297asmorkalov merged 2 commits intoopencv:4.xfrom
asmorkalov merged 2 commits intoopencv:4.xfrom
Conversation
Contributor
|
cc @sturkmen72 |
sturkmen72
reviewed
May 10, 2025
modules/imgcodecs/test/test_png.cpp
Outdated
| Mat img; | ||
|
|
||
| // If first is IHDR chunk, output shall not be empty. | ||
| // 8 means PNG sigunature length. |
Contributor
Author
There was a problem hiding this comment.
Thank you for your review, I fixed this and next line.
(IHDR does not expect the length of chunk data is 4.)
- // If first is IHDR chunk, output shall not be empty.
- // 8 means PNG sigunature length.
- // 4 means lenght of chunk.
+ // If IHDR chunk found as the first chunk, output shall not be empty.
+ // 8 means PNG signature length.
+ // 4 means length field(uint32_t).| // IHDR chunk shall be first. ( https://www.w3.org/TR/png-3/#5ChunkOrdering ) | ||
| id = read_chunk(m_chunkIHDR); | ||
| if (id != id_IHDR) | ||
| { |
Contributor
There was a problem hiding this comment.
chatGPT suggests
if (id == id_CgBI)
{
CV_LOG_ERROR(NULL, "CgBI chunk (Apple private) found as the first chunk. IHDR is expected.");
}
else
{
CV_LOG_ERROR(NULL, "IHDR chunk shall be first. This data may be broken or malformed.");
}
Contributor
Author
There was a problem hiding this comment.
I agreed to the message change.
This fix resulted in a complicated if statement, so I flattened it.
Before
if (id != id_IHDR)
{
if (id == id_CgBI)
{
CV_LOG_ERROR(NULL, "CgBI chunk (Apple private) found as the first chunk. IHDR is expected.");
}
else
{
CV_LOG_ERROR(NULL, "IHDR chunk shall be first. This data may be broken or malformed.");
}
return false;
}After
if (id == id_CgBI)
{
CV_LOG_ERROR(NULL, "CgBI chunk (Apple private) found as the first chunk. IHDR is expected.");
return false;
}
if (id != id_IHDR)
{
CV_LOG_ERROR(NULL, "IHDR chunk shall be first. This data may be broken or malformed.");
return false;
}I have also reflected this correction in the comments of the test code. Thank you very much !
asmorkalov
approved these changes
May 12, 2025
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close #27295
To optimize for the native pixel format of the iPhone's early PowerVR GPUs, Apple implemented a non-standard PNG format.
Details: https://theapplewiki.com/wiki/PNG_CgBI_Format
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.