Closed Bug 1240665 Opened 9 years ago Closed 8 years ago

Make image loading error log messages more accurate

Categories

(Core :: Graphics: ImageLib, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: daniel.f.starke, Assigned: glennrp+bmo)

References

Details

Attachments

(2 files, 10 obsolete files)

Attached image example.png
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36 Steps to reproduce: I did open a large PNG file like the one attached with Firefox ESR 38.5.2. Actual results: Firefox only shows a black page with "The image ... cannot be displayed because it contains errors." Expected results: Chrome, Internet Explorer, Photoshop or IrfanView for example show no issue in opening this file. As the file itself is totally fine, Firefox should at least display a different error than "file is broken". This is really confusing. The best solution would be to make Firefox support such PNG files.
Component: Untriaged → File Handling
Status: UNCONFIRMED → NEW
Component: File Handling → ImageLib
Ever confirmed: true
Product: Firefox → Core
QA Contact: glennrp+bmo
Assignee: nobody → glennrp+bmo
QA Contact: glennrp+bmo
Status: NEW → ASSIGNED
To get more useful information, run firefox from a console window, with NSPR_LOG_MODULES=PNGDecoder:3 in the environment. Then besides the "image cannot be displayed" screen you also get the following in the console window: [0x7f02ee2603e0]: W/PNGDecoder libpng warning: Image width exceeds user limit in IHDR [0x7f02ee2603e0]: E/PNGDecoder libpng error: Invalid IHDR data
See bug #408568 which is the same issue, but with JPEG.
To get more useful information, run firefox from a console window, with NSPR_LOG_MODULES=PNGDecoder:3 in the environment. Then besides the "image cannot be displayed" screen you also get the following in the console window: [0x7f02ee2603e0]: W/PNGDecoder libpng warning: Image width exceeds user limit in IHDR [0x7f02ee2603e0]: E/PNGDecoder libpng error: Invalid IHDR data
Summary: Error on loading large PNG files → Error "image ... cannot be displayed because it contains errors" on loading large PNG files
I did not see such a message within the console windows of my Firefox. And the JPEG bug is quite old and still unsolved. But anyway, will there be a bugfix for this or is there a workaround available? Maybe some magic setting in about:config?
In recent months I have been finding a lot of jpg and png images on Imgur which 'contain errors' on ff42 vista, but render fine on everything else. Here is a 2160 x 3840 px image of a pepsi bottle which firefox wont render http://i.imgur.com/jmxTwAp.jpg I flick through imgur gallery randomly 4 images until i get another which firefox wont render. http://i.imgur.com/Efon9ni.jpg 2546 x 1738px - a slightly crude meme I flick randomly again, this see 17 successful images before another broken jpg http://i.imgur.com/San5GYN.jpg 2895 x 2895 - a celeb mugshot Once more, just 5 images before the next broken http://i.imgur.com/p5K3PWc.jpg 2650 x 1600px - nature satelite photo or such I think ive noticed this since around ff39, it looks like a serious issue at large with the new image decoding.
However after a restart, they all load in fine. This issue's example.png does not however. Sorry if this isnt the right place to have noted my intermittent problem.
Attached patch v00-1240665-log-all-png-errors (obsolete) — Splinter Review
Some errors in image/decoders/nsPNGDecoder.cpp call png_longjmp() instead of png_error(), which bypasses the MOZ_LOG() call. This patch changes these png_longjmp() calls to png_error() calls.
Note that the two "SuccessfulEarlyFinish" calls to png_longjmp() are left intact by the v00 patch, because it's appropriate for these to not emit an error message.
Attached patch v01-1240665-log-all-png-errors (obsolete) — Splinter Review
Rebase, fix typo in one error message
Attachment #8724858 - Attachment is obsolete: true
The following link is a bug affecting imlib2. I don't know if Firefox uses or shares any of the same code but Firefox has similar symptoms (without the segfault). https://github.com/muennich/sxiv/issues/236#issuecomment-220143248 It seems that if either width or height is bigger than 32768 pixels rendering of the image fails.
Attached patch v02-1240665-log-all-png-errors (obsolete) — Splinter Review
Fix bit rot due to landing of bug #1255107
Attachment #8730023 - Attachment is obsolete: true
Why is more logging needed? ># define MOZ_PNG_MAX_DIMENSION 32767 > if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION) { >- png_longjmp(decoder->mPNG, 1); >+ png_error(decoder->mPNG," Image dimensions exceed Mozilla's limits"); > } Obviously this is the cause of the bug. The comment #0 image has 93765 px wide.
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → DUPLICATE
In my opinion, "Image dimensions exceed Mozilla's limits" is more obvious (and accurate) than "The image ... cannot be displayed because it contains errors."
Oh, is this message user-visible? I see.
Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---
Summary: Error "image ... cannot be displayed because it contains errors" on loading large PNG files → Make image loading error messages more user-friendly
It only makes the message user-visible when the user runs Firefox from a terminal/console window. It would be nice to put the libpng message in the image window, where the "The image ... cannot be displayed because it contains errors" is currently displayed, but the patch doesn't do that.
Summary: Make image loading error messages more user-friendly → Make image loading error log messages more accurate
Attached patch v03-1240665-log-all-png-errors (obsolete) — Splinter Review
Rebased after landing bug #1282566. Please "try".
Attachment #8765713 - Attachment is obsolete: true
Flags: needinfo?(ryanvm)
Comment on attachment 8766838 [details] [diff] [review] v03-1240665-log-all-png-errors "try" result is very green. R?
Attachment #8766838 - Flags: review?(seth)
Comment on attachment 8766838 [details] [diff] [review] v03-1240665-log-all-png-errors Review of attachment 8766838 [details] [diff] [review]: ----------------------------------------------------------------- Thanks Glenn! r+, but please fix the formatting issues below. ::: image/decoders/nsPNGDecoder.cpp @@ +550,5 @@ > &interlace_type, &compression_type, &filter_type); > > // Are we too big? > if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION) { > + png_error(decoder->mPNG," Image dimensions exceed Mozilla's limits"); Nit: |mPNG," Image| should be |mPNG, "Image| - in other words, the position of the quote and the space are reversed. @@ +559,5 @@ > // Post our size to the superclass > decoder->PostSize(frameRect.width, frameRect.height); > if (decoder->HasError()) { > // Setting the size led to an error. > + png_error(decoder->mPNG," Sizing error"); Same as above. @@ +672,5 @@ > > if (decoder->mDownscaler && !decoder->IsFirstFrameDecode()) { > MOZ_ASSERT_UNREACHABLE("Doing downscale-during-decode " > "for an animated image?"); > + png_error(decoder->mPNG,"Invalid downscale attempt"); // Abort the decode. Nit: there's a missing space between the comma and the quote. @@ +709,2 @@ > if (NS_FAILED(rv)) { > + png_error(decoder->mPNG,"CreateFrame failed"); Same as above. @@ +718,5 @@ > uint32_t bpp[] = { 0, 3, 4, 3, 4 }; > decoder->mCMSLine = > static_cast<uint8_t*>(malloc(bpp[channels] * frameRect.width)); > if (!decoder->mCMSLine) { > + png_error(decoder->mPNG,"malloc of mCMSLine failed"); Same as above.
Attachment #8766838 - Flags: review?(seth) → review+
(In reply to Masatoshi Kimura [:emk] from comment #12) > Why is more logging needed? > > ># define MOZ_PNG_MAX_DIMENSION 32767 > > if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION) { > >- png_longjmp(decoder->mPNG, 1); > >+ png_error(decoder->mPNG," Image dimensions exceed Mozilla's limits"); > > } > > Obviously this is the cause of the bug. The comment #0 image has 93765 px > wide. Yep, that's true. A 32767 x 32767 image is 4GB, and allocating that much memory is either dangerous or impossible on many platforms that we have to support. (We could probably relax those limits on some platforms, but it requires some careful thought; this isn't the bug to do it in.) However, we don't need to forbid images that are over 32767 in one dimension but whose total size may be much lower. The image in comment 0 is 93765px wide, but only 640px high, which works to 240MB; that's no problem. This is probably a pretty quick fix, though I need to take a look at the code and make sure we're not in danger of overflow anywhere if we naively make this change.
Since this bug is about improving the logging messages, let's just deal with that here. We'll make the image in comment 0 successfully decode in bug 1283961.
Attached patch v04-1240665-log-all-png-errors (obsolete) — Splinter Review
Nits fixed.
Attachment #8766838 - Attachment is obsolete: true
Attachment #8767378 - Flags: review?(seth)
Attached patch v05-1240665-log-all-png-errors. (obsolete) — Splinter Review
Rebased. Please transfer the r+ from the v03 patch to v05.
Attachment #8767378 - Attachment is obsolete: true
Attachment #8767378 - Flags: review?(seth)
Attachment #8770235 - Flags: review?(seth)
Attached patch v06-1240665-log-all-png-errors (obsolete) — Splinter Review
Rebased.
Attachment #8770235 - Attachment is obsolete: true
Attachment #8770235 - Flags: review?(seth)
Attachment #8772164 - Flags: review?(seth)
Attached patch v07-1240665-log-all-png-errors (obsolete) — Splinter Review
Rebased
Attachment #8772164 - Attachment is obsolete: true
Attachment #8772164 - Flags: review?(seth)
Attachment #8772919 - Flags: review?(seth)
Attached patch v08-1240665-log-all-png-errors (obsolete) — Splinter Review
Rebased again, and destroy png structs before returning from error handler. Please run this through "try".
Attachment #8772919 - Attachment is obsolete: true
Attachment #8772919 - Flags: review?(seth.bugzilla)
Flags: needinfo?(ryanvm)
Attachment #8773903 - Flags: review?(seth.bugzilla)
Attached patch v09-1240665-log-all-png-errors (obsolete) — Splinter Review
Removed incorrect line added to isValidICO().
Attachment #8773903 - Attachment is obsolete: true
Attachment #8773903 - Flags: review?(seth.bugzilla)
Please retry
Flags: needinfo?(ryanvm)
Comment on attachment 8774807 [details] [diff] [review] v09-1240665-log-all-png-errors Try B are green. R?
Attachment #8774807 - Flags: review?(tnikkel)
OS: Unspecified → All
Hardware: Unspecified → All
Version: 38 Branch → Trunk
Rebased after landing Bug #1283961
Attachment #8774807 - Attachment is obsolete: true
Attachment #8774807 - Flags: review?(tnikkel)
Attachment #8775938 - Flags: review?(tnikkel)
Attachment #8775938 - Flags: review?(tnikkel) → review+
Keywords: checkin-needed
Pushed by cbook@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/4581a6d4a620 Log all error returns from the PNG decoder. r=tnikkel
Keywords: checkin-needed
Status: REOPENED → RESOLVED
Closed: 8 years ago8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: