Embedding ZIP Files Inside JPG Files Using ColdFusion (Live Demo)

Posted January 22, 2009 at 4:10 PM by Ben Nadel

Tags: ColdFusion

Earlier this week, I posted a demonstration of how to use ColdFusion to programmatically create zip files and then embed those zip files secretly inside of JPG image files. I also demonstrated how to use ColdFusion to extract this hidden, embedded data from the resultant JPG file. In the comments to the blog post, Gary Fenton asked how to use the resultant file without using ColdFusion. On my machine, Windows XP, it's simply a matter of renaming the file extension. To make sure that we're all on the same page, I put together a quick little demo:

 
 
 
 
 
 
 
 
 
 

I can't say that this works on other versions of Windows, but XP handles it nicely.




Reader Comments

Jan 22, 2009 at 7:54 PM // reply »
15 Comments

Thanks Ben. I believe you now. :-D I'll run the code locally to generate the merged jpeg. Maybe IE did something to the image when I right-clicked and saved it from your previous blog.


Jan 22, 2009 at 9:44 PM // reply »
110 Comments

That still seems crazy to me that it works so nicely :) Really cool though.


Jan 22, 2009 at 11:03 PM // reply »
1 Comments

It should be noted that the reason this kinda thing is possible is due to the way some file formats are structured.

JPEG (as well as the various MPEGs, including MP3s) allows junk data to be included with the file - any applications designed to read those files just ignore anything that's not part of a JPEG.

Similarly programs that handle ZIP files will ignore the JPEG portion - what appears to be junk to them.

In Windows you can get away with this sort of thing, just by using file extensions - if it's a .jpg, Windows will try to use your associated image application to read it; but if it's a .zip, it'll use your default compression app.

When it comes to systems that use the actual content to try to identify file types, this may not work so well.

Various Linux frontends (like gnome/KDE) for example will probably identify the first part of the file - an image - and open it using an image editor, even if the extension is .zip (I have yet to test this - probably won't get a chance to touch my Linux boxen in the near future)

Of course, if you choose to open the file using the specific application in question, it shouldn't be a problem.

I'd be interested to see what happens if you use two different file types which can be read by the one application - for example, concatenating a raw WAV file after an mp3 or something, and seeing how winamp/media player handles it (or jpg/png for a smaller test).

-J


Jan 23, 2009 at 1:40 AM // reply »
34 Comments

Ben - Just one more post till your 1000th Cold fusion post :)
hahahahaha!


Jan 23, 2009 at 8:25 AM // reply »
211 Comments

BTW, I was a big WinRAR fan too, but it's time to move to 7-Zip ( http://www.7-zip.org/ ).


Jan 23, 2009 at 9:11 AM // reply »
110 Comments

@Todd
Cool. I didn't know that it handled RAR files also. I'll have to see how much quicker it is that WinRAR.


Jan 23, 2009 at 9:15 AM // reply »
211 Comments

@Gareth: It can only un-rar a .rar file. Can't create.


Jan 23, 2009 at 9:34 AM // reply »
10,640 Comments

@Todd,

Looks cool. Anything in particular that I should know about it?

@Paolo,

Thanks for pointing that - that's kind of cool. Maybe today :D


Jan 23, 2009 at 9:38 AM // reply »
211 Comments

@Ben: It's free? It doesn't nag you like winrar does? :) It's also open-source. I've seen mixed results between 7-Zip files (.7z) and Winrar (.rar), majority of the times 7-Zip won in the compression size. The max compression is still .zip (which 7-Zip still handles). Otherwise, it will un-rar, un-zip, un-7z, etc.


Jan 23, 2009 at 9:39 AM // reply »
10,640 Comments

@Todd,

Sounds good to me. I do like free :) I'll give it a look-see.


Jan 23, 2009 at 9:41 AM // reply »
211 Comments

And, if you don't like the 7z interface, you could use jZip ( http://www.jzip.com/ ) - which uses the 7z compression engine and basically gives it a better facelift.


Feb 19, 2009 at 1:42 AM // reply »
1 Comments

Thats interesting info.!!


Oct 7, 2009 at 11:56 PM // reply »
1 Comments

If you were to use "Open With..." and select 7zip, you wouldn't even need to change the extension. :)


May 22, 2010 at 1:05 PM // reply »
1 Comments

try http://www.openrarfile.com/open-rar-file

nothing to download, all webbased



Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 12, 2012 at 3:37 AM
Learning ColdFusion 8: CFImage Part III - Watermarks And Transparency
Hi Ben, Just to ask currently it is placed bottom right corner, if i need to replace the same rendered image on the bottom left side or in the bottom center, how that can be calculated. bottom ce ... read »
Feb 11, 2012 at 9:29 PM
Use jQuery's SlideDown() With Fixed-Width Elements To Prevent Jumping
I can't say how glad I am that I found your post. Thank you very much. ... read »
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »