syvaidya / openstego

OpenStego is a steganography application that provides two functionalities: a) Data Hiding: It can hide any data within an image file. b) Watermarking: Watermarking image files with an invisible signature. It can be used to detect unauthorized file copying.
https://www.openstego.com
GNU General Public License v2.0
1.13k stars 206 forks source link

javax.imageio.IIOException: JFIF APP0 must be first marker after SOI #55

Closed KirkStallings closed 1 year ago

KirkStallings commented 2 years ago

When trying to verify the watermark of the output / watermarked file, the program throws the error in the title.

I believe this may have to do with the size of the input file. My input file is 3.5 MB.

Expected: When clicking "Verify watermark" in the "Verify watermark" window (part of Digital watermarking (Beta), I expect to see the window that tells what percentage the watermark file matches the signature file.

Observed: The program displays an error window with the message "javax.imageio.IIOException: JFIF APP0 must be first marker after SOI". The program does not crash though. Upon looking at the file sizes, I see the input file was 3592 KB and the watermarked file was only 636 KB. I don't think this downsize is supposed to happen so maybe the error is during the "Embed watermark" part and the badly formatted watermarked file is causing "Verify watermark" to hit the error. Running "Verify watermark" on the original image (3.5 MB) generates the correct Results window showing a 0% strength match.

Files: https://drive.google.com/drive/folders/1Xu12Q7EzrWNzxmKJYf0TrLD5aA6pqy6k?usp=sharing Copyright_Sig.sig is the generated signature file using input text Copyright 2022 The Tabletop Market input_image.jpg is the large input file watermarked_image.jpg is what was generated by the OpenStego program.

I am running Windows 10 Pro with java version "18.0.2.1" 2022-08-18 I am running OpenStego "installed" rather than batch file start.

syvaidya commented 1 year ago

Thanks for the report. I'll take a look.

syvaidya commented 1 year ago

The file size reducing to 636KB is not an issue, because OpenStego saves JPEG files with compression quality of 75. Your original file has 98 quality so it is large. You can change output JPEG quality by editing openstego.ini file that gets created in your user home directory, and then restarting OpenStego.

I am trying to debug now why your JPEG is giving JFIF APP0 error.

syvaidya commented 1 year ago

Fixed with v0.8.5.

Many (or most?) JPEG readers are lenient and allow JPEG files where APP0 marker is not the first one in JFIF metadata - which is the case with image in this issue. But Java ImageIO is strict and not allowing it. One option is that I switch to some other image handling library like TwelveMonkey, but it would be large effort and would add dependency to that library.

So for now, OpenStego will just discard metadata for such JPEG files.

Refer to https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6488904 for details.

Bluexin commented 9 months ago

@syvaidya JFYI since I just fixed this issue in one of my own apps (stumbled across this issue while looking for free to use images for our automated testing), the fix was as easy as adding a dependency to the TwelveMonkey plugin for it as described here As it is a plugin to the ImageIO library (which uses ServiceLoader to load format-specific SPIs) and it inserts itself before the default handler for JPEG, having the required library on the classpath is all that is required to work around this issue.

syvaidya commented 8 months ago

@syvaidya JFYI since I just fixed this issue in one of my own apps (stumbled across this issue while looking for free to use images for our automated testing), the fix was as easy as adding a dependency to the TwelveMonkey plugin for it as described here As it is a plugin to the ImageIO library (which uses ServiceLoader to load format-specific SPIs) and it inserts itself before the default handler for JPEG, having the required library on the classpath is all that is required to work around this issue.

Thanks @Bluexin. Yes I am aware of TwelveMonkey fix, but I want to avoid any dependencies in my project. There is the issue of differences in GPL (openstego) and BSD (twelvemonkey) licensing and I am not sure if I can combine both. Another issue is the size of binary - twelvemonkey binaries are larger that openstego, so essentially just to fix this issue, I'll more than double the size of the dist.