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

"palette index exceeding num_palette" error after upgrade to libpng 1.6.44 #653

Open
ashishpmw opened this issue Feb 3, 2025 · 1 comment

Comments

@ashishpmw
Copy link

Dear libpng community,

We are seeking guidance on "palette index exceeding num_palette" error after upgrade to libpng 1.6.44
We've recently upgraded our application from libpng 1.6.37 to 1.6.44 and have encountered an issue when writing indexed color PNGs. Specifically, we're receiving the error: "libpng error: Wrote palette index exceeding num_palette".

We've created a standalone application to reproduce this issue consistently, I have attached the folder containing the source code along with exe files generated for the respective version. Here are the details:
Input:
• We create an indexed image with values 1 through 10.
• We define a colormap with 10 entries (indices 0-9).

Output with libpng 1.6.37:
Actual Indexed data:
1 2 3 4 5 6 7 8 9 10
Colormap:
Index 0: R=0.2422 G=0.1504 B=0.6603
Index 1: R=0.2803 G=0.2782 B=0.9221
Index 2: R=0.244 G=0.4358 B=0.9988
Index 3: R=0.154 G=0.5902 B=0.9218
Index 4: R=0.0297 G=0.7082 B=0.8163
Index 5: R=0.1938 G=0.7758 B=0.6251
Index 6: R=0.5044 G=0.7993 B=0.348
Index 7: R=0.8634 G=0.7406 B=0.1596
Index 8: R=0.9892 G=0.8136 B=0.1885
Index 9: R=0.9769 G=0.9839 B=0.0805
**

Testcode.zip

**

Output with libpng 1.6.44:
Actual Indexed data:
1 2 3 4 5 6 7 8 9 10
Colormap:
Index 0: R=0.2422 G=0.1504 B=0.6603
Index 1: R=0.2803 G=0.2782 B=0.9221
Index 2: R=0.244 G=0.4358 B=0.9988
Index 3: R=0.154 G=0.5902 B=0.9218
Index 4: R=0.0297 G=0.7082 B=0.8163
Index 5: R=0.1938 G=0.7758 B=0.6251
Index 6: R=0.5044 G=0.7993 B=0.348
Index 7: R=0.8634 G=0.7406 B=0.1596
Index 8: R=0.9892 G=0.8136 B=0.1885
Index 9: R=0.9769 G=0.9839 B=0.0805
libpng error: Wrote palette index exceeding num_palette

Error Description:
The error occurs when writing the image data, specifically when encountering the value 10, which exceeds the highest valid palette index of 9. This use-case worked correctly with version 1.6.37 but is now causing errors with 1.6.44.

Seeking Your Insights on:
• Is libpng 1.6.44 enforcing stricter checks on palette index values compared to the previous version?
• Has there been a change in how indexed color PNGs are handled in the 1.6.44 release?
• Are there any known workarounds or best practices to address the discrepancy between our image data and palette indices?

We appreciate any insights or assistance the community can provide. Thank you for your time and expertise.

Thanks & Regards,
Ashish

@jbowler
Copy link
Contributor

jbowler commented Feb 3, 2025

That's the way it was meant to work since the test was added in libpng1.5.

It was broken in 1.6.33 and the bug was identified by Adam Richter (in 2020) and fixed by his change 866fdf6, committed in January of last year, so in 1.6.41:

866fdf6

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