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

Length of Scan segment can be off if there are restart markers #8

Open
mauricefisher64 opened this issue Feb 12, 2024 · 2 comments
Open

Comments

@mauricefisher64
Copy link
Contributor

In reader.rs read_scan_data function should kick out not just for 0x00 but also for any restart segment (RSTn).

             if byte != 0x00 {
                self.current_marker = Some(byte);
                break;
            } else {
                for _ in 0..ff_count {
                    data.push(0xFF);
                }
                data.push(byte);
            }

I think it should be something like this:

fn in_entropy(marker: u8) -> bool {
matches!(marker, 0xd0..=0xd7 | 0x00)
}

              if !in_entropy(byte) {
                self.current_marker = Some(byte);
                break;
            } else {
                for _ in 0..ff_count {
                    data.push(0xFF);
                }
                data.push(byte);
            }
@mauricefisher64
Copy link
Contributor Author

I think there also needs to be a rollback of the position pointer - 2 when !in_entropy(byte) is true since you have read the 0xFF and byte (the next tag). Otherwise the size will be off by two bytes since this code just detected the next tag.

@vstroebel
Copy link
Owner

Even if not technically correct, the current implementation treats restart markers like normal segments because I need this information for my personal use case.
Your solution would completely remove the existence of restart markers from the dump.

One possible alternative is to extend the Scan struct to include all restarts as individual data parts. But this could make reading/dumping broken JPEG file more complicated.

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

No branches or pull requests

2 participants