ImHex-Patterns
ImHex-Patterns copied to clipboard
Support EOF in the middle of JPEG
- Support for EOF if EOF in the JPEG met not in the end.
Before
After
JPEG to reproduce
More information in #239
Hey! Thanks a lot for the PR
There seems to be an issue with your changes that makes the CI fail to run with the jpeg test file we're using. Could you check what happened there?
I'm not sure, but I think there is a bug in find_sequence from pattern language.
I am using this image for tests and std::print for debug:
struct SOS {
u8 numComponents;
SOSComponent components[numComponents];
u8 startSpectralSelection;
u8 endSpectral;
u8 apprBitPos;
std::print("{}", std::mem::find_sequence(0, 0x8F, 0xD0, 0xFF, 0x00, 0xFF));
u8 image_data[std::mem::size() - $ - 2] [[sealed]];
};
And I got this result, and it's correct:
But when I change std::print("{}", std::mem::find_sequence(0, 0x8F, 0xD0, 0xFF, 0x00, 0xFF)); to std::print("{}", std::mem::find_sequence(0, 0x8F, 0xD0, 0xFF, 0x00, 0xFF, 0xD9)); I got a wrong result:
Looks like
find_sequence is not checking the most last byte.
I ask ChatGPT about this code, and this is what I got:
It's hard for me to confirm this, but can I kindly ask you to check this bug?
It wasn't that hard to verify the error. After getting -1 when the last byte of the file was included in the search I resized the input file by adding an extra byte at the end and then the search including 0xD9 was correct again.
It looks like the unit test fails because it uses the result of the find sequence function to calculate an array size. Because of the bug you found, the find sequence function is returning -1 which is not a valid array size. Although all jpegs must include this sequence it is a good idea to check the result of the find sequence function for failure to find it (eg file was corrupted) so you can print a better error message (like "missing eof sequence" or something) instead of the "-1 is not a valid array size" that it prints currently.
Ready to check
Ping
Thank you!