ImHex-Patterns icon indicating copy to clipboard operation
ImHex-Patterns copied to clipboard

Support EOF in the middle of JPEG

Open vodkar opened this issue 1 year ago • 4 comments

  • Support for EOF if EOF in the JPEG met not in the end.

Before

image

After

image

JPEG to reproduce

Schematic 53c1dec

More information in #239

vodkar avatar Apr 14 '24 21:04 vodkar

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?

WerWolv avatar Apr 21 '24 10:04 WerWolv

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: image

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: image Looks like find_sequence is not checking the most last byte. I ask ChatGPT about this code, and this is what I got:

image

It's hard for me to confirm this, but can I kindly ask you to check this bug?

vodkar avatar Apr 27 '24 17:04 vodkar

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.

paxcut avatar Apr 27 '24 18:04 paxcut

Ready to check

vodkar avatar May 21 '24 15:05 vodkar

Ping

vodkar avatar Jun 16 '24 13:06 vodkar

Thank you!

WerWolv avatar Jun 16 '24 13:06 WerWolv