Algorithm for check JPEG format

Hi! I need to check if a JPEG file is ok. I can't use any multimedia library. Anybody knows how can determine if a file is a JPEG file, and it's ok.Cheers!
[171 byte] By [OcELLa] at [2007-10-2 22:01:18]
# 1

read this

http://www.w3.org/Graphics/JPEG/jfif3.pdf

Its fairly easy to determine if a file is FIF. Its harder to tell if it is valid (you need to parse the file completely for required markers and ensure they are valid, then examine the data to see if it complies). JPEG streams can be used in a variety of file formats so even if the file is not a FIF it could still be JPEG (i.e. TIFF)

matfud

matfuda at 2007-7-14 1:17:34 > top of Java-index,Other Topics,Algorithms...
# 2
Check out reply 7 on this thread: http://forum.java.sun.com/thread.jspa?threadID=554733&messageID=2717319It contains the primitive workings to check the first two bytes and get the dimensions of the JPEG.
rkippena at 2007-7-14 1:17:34 > top of Java-index,Other Topics,Algorithms...
# 3
It seems good! I only need to chek if the JPEG image is ok for later proces with another application (that crash if JPEG isn' ok :-S).Thanks in advance!OcELL
OcELLa at 2007-7-14 1:17:34 > top of Java-index,Other Topics,Algorithms...
# 4
We are also having a problem with invalid JPEG crashing the JVM.. any idea?ThanksHemant
hsativadaa at 2007-7-14 1:17:35 > top of Java-index,Other Topics,Algorithms...
# 5

That's surprising that the whole JVM crashes. I didn't think that was possible. File a bug report, maybe you'll get 5 minutes of fame.

On a serious note:

Is it really crashing the JVM or is it just causing your application to crash?

Can any applications open the JPEG in question?

rkippena at 2007-7-14 1:17:35 > top of Java-index,Other Topics,Algorithms...
# 6

Here are some bug reports, but it is a bug in progress and fixed only in 1.5

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4836529

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4845461

Is it really crashing the JVM or is it just causing your application to crash?

The whole jvm crahes and brings down the server

Can any applications open the JPEG in question?

No other applications can open the JPEG, it is a corrupt JPEG. Not sure how to identify it though.

hsativadaa at 2007-7-14 1:17:35 > top of Java-index,Other Topics,Algorithms...
# 7
Can you put the file somewhere publicly available?I'll try something after I get home from work.
rkippena at 2007-7-14 1:17:35 > top of Java-index,Other Topics,Algorithms...