-
Notifications
You must be signed in to change notification settings - Fork 32
Fix PNG loader not resetting stream position on error right after reading signature #387
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,11 @@ namespace LV { | |
|
|
||
| png_byte signature[8]; | ||
| input.read (reinterpret_cast<char*> (signature), sizeof (signature)); | ||
| input.seekg (saved_stream_pos); | ||
|
|
||
| if (!input) { | ||
|
||
| return nullptr; | ||
| } | ||
|
|
||
| bool is_png = !png_sig_cmp (signature, 0, sizeof (signature)); | ||
|
|
||
|
|
@@ -100,6 +105,8 @@ namespace LV { | |
| return nullptr; | ||
| } | ||
|
|
||
| input.seekg (sizeof (signature), std::ios::cur); | ||
|
|
||
| png_set_read_fn (png_ptr, &input, handle_png_read); | ||
|
|
||
| png_set_sig_bytes (png_ptr, sizeof (signature)); | ||
|
|
||
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.
seekgcould kill an error state flag set byreadabove? I'm having trouble finding docs whether error flags are set until reset by the user or being auto-reset by every new API call?input.seekg (saved_stream_pos);in line 93 being still needed or no longer needed?Uh oh!
There was an error while loading. Please reload this page.
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.
According to this,
seekg():eofflag before anything elsefail() != true(i.e. eitherbadorfailflags are set)So there are two failure scenarios:
eofandfailflags are set, soseekg()does nothing. Clearly bad.eofis set.seekg()clears theeofand resets the input position. Okay, the decoding runs after and read errors will be caught there and then.Did you mean line 98? Indeed, any read failure prior to that clean up routine will prevent the position reset, so we need to clear the
failflag withclear().So, back to the drawing board..