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

Webp: cannot decode grayscale images #841

Closed
gotson opened this issue Oct 19, 2023 · 5 comments
Closed

Webp: cannot decode grayscale images #841

gotson opened this issue Oct 19, 2023 · 5 comments

Comments

@gotson
Copy link
Contributor

gotson commented Oct 19, 2023

Describe the bug
This was reported in my own project Komga, where a user has webp images that are encoded in grayscale. The image reader throws an exception on read.

Version information

  1. The version of the TwelveMonkeys ImageIO library in use: 3.9.4

  2. The exact output of java --version (or java -version for older Java releases).

openjdk version "21" 2023-09-19 LTS
OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS)
OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode)
  1. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.

MacOS Sonoma 14.0
Apple M1 Pro

To Reproduce
Steps to reproduce the behavior:

  1. Add the file in the test resources in the project
  2. Run the testRead test method
  3. Check stack trace below

Expected behavior
The image should be decoded.

Sample file(s)
Attach any sample files needed to reproduce the problem. Use a ZIP-file if the format is not directly supported by GitHub.

07_Ghost_01_[TnS]_002.zip

Stack trace

/Users/groebroeck/.sdkman/candidates/java/21-tem/bin/java -ea -Didea.test.cyclic.buffer.size=10485760 -javaagent:/Users/groebroeck/Applications/IntelliJ IDEA Ultimate.app/Contents/lib/idea_rt.jar=53984:/Users/groebroeck/Applications/IntelliJ IDEA Ultimate.app/Contents/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Users/groebroeck/Applications/IntelliJ IDEA Ultimate.app/Contents/lib/idea_rt.jar:/Users/groebroeck/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/junit/lib/junit5-rt.jar:/Users/groebroeck/Applications/IntelliJ IDEA Ultimate.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/groebroeck/Dev/TwelveMonkeys/imageio/imageio-webp/target/test-classes:/Users/groebroeck/Dev/TwelveMonkeys/imageio/imageio-webp/target/classes:/Users/groebroeck/Dev/TwelveMonkeys/imageio/imageio-core/target/classes:/Users/groebroeck/Dev/TwelveMonkeys/imageio/imageio-metadata/target/classes:/Users/groebroeck/Dev/TwelveMonkeys/imageio/imageio-core/target/test-classes:/Users/groebroeck/Dev/TwelveMonkeys/common/common-lang/target/classes:/Users/groebroeck/Dev/TwelveMonkeys/common/common-io/target/classes:/Users/groebroeck/Dev/TwelveMonkeys/common/common-image/target/classes:/Users/groebroeck/Dev/TwelveMonkeys/common/common-lang/target/test-classes:/Users/groebroeck/Dev/TwelveMonkeys/common/common-io/target/test-classes:/Users/groebroeck/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/Users/groebroeck/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/groebroeck/.m2/repository/org/mockito/mockito-core/4.11.0/mockito-core-4.11.0.jar:/Users/groebroeck/.m2/repository/net/bytebuddy/byte-buddy/1.12.19/byte-buddy-1.12.19.jar:/Users/groebroeck/.m2/repository/net/bytebuddy/byte-buddy-agent/1.12.19/byte-buddy-agent-1.12.19.jar:/Users/groebroeck/.m2/repository/org/objenesis/objenesis/3.3/objenesis-3.3.jar:/Users/groebroeck/.m2/repository/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderTest,testRead
java.lang.IllegalArgumentException: bandOffsets.length is wrong!
	at java.desktop/javax.imageio.ImageTypeSpecifier$Interleaved.<init>(ImageTypeSpecifier.java:286)
	at java.desktop/javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:395)
	at com.twelvemonkeys.imageio.util.ImageTypeSpecifiers.createInterleaved(ImageTypeSpecifiers.java:156)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReader.getRawImageType(WebPImageReader.java:390)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReader.getImageTypes(WebPImageReader.java:398)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReader.read(WebPImageReader.java:417)
	at java.desktop/javax.imageio.ImageReader.read(ImageReader.java:938)
	at com.twelvemonkeys.imageio.util.ImageReaderAbstractTest.testRead(ImageReaderAbstractTest.java:223)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderTest.testRead(WebPImageReaderTest.java:194)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

java.lang.AssertionError: Image file:/Users/groebroeck/Dev/TwelveMonkeys/imageio/imageio-webp/target/test-classes/webp/gray.webp index 0 could not be read: java.lang.IllegalArgumentException: bandOffsets.length is wrong!

	at com.twelvemonkeys.imageio.util.ImageReaderAbstractTest.failBecause(ImageReaderAbstractTest.java:107)
	at com.twelvemonkeys.imageio.util.ImageReaderAbstractTest.testRead(ImageReaderAbstractTest.java:227)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderTest.testRead(WebPImageReaderTest.java:194)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.IllegalArgumentException: bandOffsets.length is wrong!
	at java.desktop/javax.imageio.ImageTypeSpecifier$Interleaved.<init>(ImageTypeSpecifier.java:286)
	at java.desktop/javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:395)
	at com.twelvemonkeys.imageio.util.ImageTypeSpecifiers.createInterleaved(ImageTypeSpecifiers.java:156)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReader.getRawImageType(WebPImageReader.java:390)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReader.getImageTypes(WebPImageReader.java:398)
	at com.twelvemonkeys.imageio.plugins.webp.WebPImageReader.read(WebPImageReader.java:417)
	at java.desktop/javax.imageio.ImageReader.read(ImageReader.java:938)
	at com.twelvemonkeys.imageio.util.ImageReaderAbstractTest.testRead(ImageReaderAbstractTest.java:223)
	... 26 more
@haraldk
Copy link
Owner

haraldk commented Oct 19, 2023

Interesting...

I wasn't even aware that the format supported grayscale images. 😬

This StackOverflow Q/A seems to conclude it does not, and reading the specification myself I can't find a single mention of the words "grey" or "gray"... 🤷🏻

@haraldk
Copy link
Owner

haraldk commented Oct 19, 2023

Actually, this is a plain RGB WebP, but with a grayscale ICC profile...

The fix is quite simple, we'll just ignore the ICC profile.

@gotson
Copy link
Contributor Author

gotson commented Oct 19, 2023

Actually, this is a plain RGB WebP, but with a grayscale ICC profile...

The fix is quite simple, we'll just ignore the ICC profile.

that's what i found too, and i did the same fix in NightMonkeys :)

@gotson
Copy link
Contributor Author

gotson commented Oct 19, 2023

Actually, this is a plain RGB WebP, but with a grayscale ICC profile...

I'm interested how you found out that. I checked with webpinfo but didn't find much. While debugging the code i could see that the color space was of type Gray, but that's it.

@haraldk
Copy link
Owner

haraldk commented Oct 19, 2023

A combination of educated guess and debugging. Got lucky. 😀

@haraldk haraldk closed this as completed Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants