Like Tracy, I attempt to answer my own questions. <g> Here's what I've figured out for anyone who might find this useful.
In order to identify a file with a JPG extension that isn't really a JPG, examine the ASCII values of the first 2 characters. The first two ASCII values of a JPG are: ASCII 255 & ASCII 216 (0xFF 0xD8). If the first two characters don't match those two values, the file is not a JPG. (If you want to be more precise about it, you can actually look for other values in specific positions in roughly the first ~16 characters but checking the first 2 characters is good enough for my purposes at the moment.) In order to identify a truncated JPG, examine the last 2 characters. The ASCII values for last two characters of a JPG are ASCII 255 & ASCII 217 (0xFF 0xD9). If the last two characters don't match those two values, then image data is missing. The minimum file size for a JPG, as best I can determine is 304 bytes. Any file smaller than that is corrupt and contains no image info at all. There are many ways to do these tests in VFP so I'm not bothering to post any code here. If anyone is interested in my solution, let me know and I'll post some snippets. rk -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Richard Kaye Sent: Monday, August 23, 2010 3:40 PM To: [email protected] Subject: truncated JPG detection In my main app I have a few ways of "attaching" images to items and every now and then, I have a user who attaches bad JPGs. A bad JPG could be a zero byte file; a file with a JPG extension that really isn't a JPG (thank you, MS...); or some variation of a truncated JPG. I've worked out some validation code that can handle the first two and at least one type of truncated JPG but I'm looking to add one more test: specifically, when the JPG header/metadata is intact but the actual number of compressed bytes stored on disk is less than it should be. Visually, you can usually see this because the JPG appears partially rendered. I've been poking around using the interwebs and the Google looking for some ideas that will allow me to determine this and was wondering if anyone here has any advice. (Right now, I'm playing around with the GDIPlusX classes but while I'm doing that I thought I'd throw this out to the list and see what comes back.) TIA, rk [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/df1eef11e586a64fb54a97f22a8bd0441900310...@ackbwddqh1.artfact.local ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

