Open Bug 1862235 Opened 1 year ago Updated 3 months ago

PNG with out-of-range palette indices in tRNS incorrectly handled

Categories

(Core :: Graphics: ImageLib, defect)

Firefox 120
x86_64
Windows 10
defect

Tracking

()

Tracking Status
firefox120 --- affected

People

(Reporter: chris, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0

Steps to reproduce:

Run http://wpt.live/png/trns-chunk.html

Actual results:

Fail

Expected results:

Pass

Test passes in Chrome (and Edge) and Safari.

The PNG specification had an ambiguity in the Second Edition:
https://www.w3.org/TR/2003/REC-PNG-20031110/#11tRNS

If the image bit depth is less than 16, the least significant bits are used and the others are 0.

After a bug report
https://github.com/w3c/PNG-spec/issues/96

this was clarified in Third Edition
https://w3c.github.io/PNG-spec/#11tRNS

If the image bit depth is less than 16, the least significant bits are used. Encoders should set the other bits to 0, and decoders must mask the other bits to 0 before the value is used.

The referenced WPT tests specifically for this updated text.

Put link from description on Win11x64 using FF build 120.0b4 and it failed, while on Chrome passed.
Marking issue as new, not sure if component is correct please update if otherwise. Thank you.

Status: UNCONFIRMED → NEW
Component: Untriaged → Top Sites
Ever confirmed: true
OS: Unspecified → Windows 10
Hardware: Unspecified → x86_64

The severity field is not set for this bug.
:jteow, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(jteow)
Component: Top Sites → Graphics
Flags: needinfo?(jteow)
Product: Firefox → Core
Component: Graphics → Graphics: ImageLib

The severity field is not set for this bug.
:tnikkel, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(tnikkel)
Severity: -- → S3
Flags: needinfo?(tnikkel)

In previous editions of the spec, out-of-range values were not
considered. As this is now specified, we should let libpng do the right
thing and not inject non-compliant behavior.

Assignee: nobody → lucas.chollet
Status: NEW → ASSIGNED

I started to investigate this issue, and there is code in nsPNGDecoder.cpp that was purposely written to have the unwanted behavior. It seems that there used to be some PNG images that had out-of-range palette indices in the wild, and that it was chosen to discard transparency in this case (bug #428045). As mentioned above, this is not spec compliant with regard to the third edition.

Removing these few lines makes the bug disappear and Firefox pass the WPT test, thus compliant to the newest PNG standard.

As you can see, I submitted a patch for it. I'm hoping I did nothing wrong, this is my first contribution here.

The bug assignee is inactive on Bugzilla, so the assignee is being reset.

Assignee: lucas.chollet → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: