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

Overflow in ForwCompTransf.calcMixedBitDepths #48

Open
Daniel-Alievsky opened this issue Jul 23, 2024 · 0 comments
Open

Overflow in ForwCompTransf.calcMixedBitDepths #48

Daniel-Alievsky opened this issue Jul 23, 2024 · 0 comments

Comments

@Daniel-Alievsky
Copy link

While using SCIFIO JPEG2000 codec, based on jai-imageio-jpeg2000, we have an exception while an attempt to encode 32-bit integer pixel samples:

Exception in thread "main" java.lang.IllegalArgumentException: 0 <= 0
at jj2000.j2k.util.MathUtil.log2(MathUtil.java:67)
at jj2000.j2k.image.forwcomptransf.ForwCompTransf.calcMixedBitDepths(ForwCompTransf.java:235)
at jj2000.j2k.image.forwcomptransf.ForwCompTransf.initForwICT(ForwCompTransf.java:307)
at jj2000.j2k.image.forwcomptransf.ForwCompTransf.setTile(ForwCompTransf.java:762)
at jj2000.j2k.image.ImgDataAdapter.setTile(ImgDataAdapter.java:288)
at jj2000.j2k.image.ImgDataAdapter.setTile(ImgDataAdapter.java:288)
at jj2000.j2k.wavelet.analysis.ForwWTFull.setTile(ForwWTFull.java:903)
at jj2000.j2k.image.ImgDataAdapter.setTile(ImgDataAdapter.java:288)
at jj2000.j2k.image.ImgDataAdapter.setTile(ImgDataAdapter.java:288)
at jj2000.j2k.roi.encoder.ROIScaler.setTile(ROIScaler.java:696)
at jj2000.j2k.image.ImgDataAdapter.setTile(ImgDataAdapter.java:288)
at jj2000.j2k.entropy.encoder.StdEntropyCoder.setTile(StdEntropyCoder.java:1267)
at jj2000.j2k.entropy.encoder.EBCOTRateAllocator.(EBCOTRateAllocator.java:281)
at jj2000.j2k.entropy.encoder.PostCompRateAllocator.createInstance(PostCompRateAllocator.java:260)
at com.github.jaiimageio.jpeg2000.impl.J2KImageWriter.write(J2KImageWriter.java:347)

The reason is the following code:

tdepth[0] = MathUtil.log2((1<<ntdepth[0])+(2<<ntdepth[1])+
                                      (1<<ntdepth[2])-1)-2+1;

When ntdepth[0]==32 (32 bits/sample), the << operator leads to 32-bit overflow and actually returns 1 instead of 1^32.

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

1 participant