-
Notifications
You must be signed in to change notification settings - Fork 284
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
Fix pixelwidth and pixelheight for raf files #810
Conversation
Codecov Report
@@ Coverage Diff @@
## master #810 +/- ##
==========================================
+ Coverage 70.94% 70.99% +0.05%
==========================================
Files 147 147
Lines 19268 19306 +38
==========================================
+ Hits 13669 13706 +37
- Misses 5599 5600 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to have a new system test (check tests under the tests
folder) to make sure that your changes are fixing the issue.
Normally we create first a python test for reproducing the detected issue and then you can apply the fix (preferentially the fix and the test in different commits). In #792 you can find an example of this procedure. Note that for providing a sample image, we remove the image content and we just keep the metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
I've added some comments myself. A test case would be nice as @piponazo noted.
src/rafimage.cpp
Outdated
@@ -296,6 +292,37 @@ namespace Exiv2 { | |||
io_->read(jpg_img_length, 4); | |||
long jpg_img_off = Exiv2::getULong((const byte *) jpg_img_offset, bigEndian); | |||
long jpg_img_len = Exiv2::getULong((const byte *) jpg_img_length, bigEndian); | |||
byte cfa_header_offset [4]; | |||
io_->read(cfa_header_offset, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before doing all these reads, please check that the image is actually large enough, or check the return value of each io_->read()
.
src/rafimage.cpp
Outdated
io_->read(byte_count, 4); | ||
byte byte_tag[2]; | ||
byte byte_size[2]; | ||
int32_t count = getLong(byte_count, bigEndian); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a sanity check for this value, otherwise this will create a near-infinite loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a sane value for you? The used test file has 32 tags, but I have no clue if other RAF files have a different number of raf tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no upper limit mandated by a standart, then you can make a rough check like: enforce(count < remaining_file_size/size_of_a_tag);
, provided that this is at least an order of magnitude less than the maximum value of int32_t
for all reasonable files.
If I understand your code, then aren't you searching for the pixelwidth and pixelheight inside the cfa_hdr
? And you've just extracted its length a few lines above, so given the tag size and the length, that gives you a pretty good upper limit on the number of tags that can possibly exist in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tag size is not constant according to exiftool, but I guess I could add a check with the minimal size for at least something
Thanks for the feedback. I will try to implement it, but I am quite busy the next weeks. Regarding the unit test, I expected and somewhat feared this request :)
Any suggestions welcome. |
No problem & no rush.
You don't have to write a unit test, an integration test would be easier imho. We have a custom integration test framework written in Python (take a look at the Python files in
|
That does not seem to work, probably because it is a raw file and the size information is also in the custom RAF metadata. I have a RAF image which the user granted me the rights to upload, but it is 31 MB. Is this a problem? |
Kind of, we do not want to add a 31 MB file to git and even for git LFS it's Is it possible to scale this file down, e.g. to 100x100 px? |
According to the user, no (I asked for lowest quality and resolution). Again, probably because it is a raw file. I found https://rawsamples.ch/index.php/en/fuji which is content provided under Creative Commons and provides a 6 MB raf file. Is this acceptable? |
Unfortunately 6 MB is still too much to be checked into git. I've created #896 to enable git lfs, so that we can add your test file. |
af8269e
to
072f910
Compare
Finally found some time again to work on this. I've rebased and added error handling as requested. |
Thanks @astippich for the contribution. The changes look good to me (the formatting is not satisfying the clang-format style we have defined, but that's something we could clean-up later, unless you do not mind to add an additional commit applying clang-format to your additions [not to the complete file]). However as @D4N already mentioned, we should not include such a big binary file in the repository. Until we add support for git LFS, or other strategy to deal with such big files, I would propose to drop the commit including the test and the binary file. Maybe we could keep a patch of that commit in this PR for future reference. Or if you guys have any other better idea, it will be welcomed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks better now, thanks for the changes.
- Please add an explanation to the chunk
readMetadata()
what you are doing there (something high level and if it makes sense, link to the issue that you reported). - Consider using the
--grep
function fromexiv2
in the test file to grep for the relevant metadata only.
Not really, beside waiting until we enable git LFS. |
I added a sentence to the code, if you want more let me know
I tried that, but could not find any documentation on what tag name to use. Could it be that this also works only for Exif tag names? I will open a separate PR for the test so that you can merge when the infrastructure is ready. |
I was hoping for a something that will explain the future maintainer (i.e. me or someone else from the team) how the format looks like that you are parsing. Currently, I have to read all your code and try to find out what it does. If you could explain that for someone that doesn't have your knowledge, that would be greatly appreciated.
@clanmills do you know that?
I think setting up git lfs has been long overdue, I'll try to look into that soon. |
Anything to do here from my side? |
Sorry for the delay on getting this merged @astippich . I'll let @D4N take care of merging it, since the PR is pending on his approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience and your effort!
Extract the pixel width and pixel height of raf images from the raf metadata found in fuji raw files.
Code inspired by exiftool
Fixes #755