Skip to content
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

Support EOF in the middle of JPEG #240

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

vodkar
Copy link

@vodkar vodkar commented Apr 14, 2024

  • 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 vodkar changed the title #239: Support EOF in the middle of JPEG Support EOF in the middle of JPEG Apr 14, 2024
@WerWolv
Copy link
Owner

WerWolv commented Apr 21, 2024

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?

@vodkar
Copy link
Author

vodkar commented Apr 27, 2024

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?

@paxcut
Copy link
Contributor

paxcut commented Apr 27, 2024

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.

@vodkar
Copy link
Author

vodkar commented May 21, 2024

Ready to check

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.

None yet

3 participants