Appending one file to the end of another

2

I know from guides like this that it's pretty easy to add a RAR archive to the end of a JPG. What I'm wanting to know is whether it's only JPG files that can handle extra data at the end, and whether I can append any arbitrary binary blob to the end of a JPG. I don't care whether the file I append to the end will be recognized by its program, I only care that the JPG appears exactly the same to image viewers.

To give a bit more specific information about my use case, I'm trying to implement a backup mechanism in a webapp focused on mobile devices. I need this to work for iOS, so the only avenue available is to use data stashed in an image file. It is a bit clunky, but humor me in understanding that it makes sense in this use case. In the link above it is shown that RAR files appended to a JPG can still be opened, as I imagine that it's not required for RARs to be at an offset of zero within a given file, and that archive applications will look for the RAR's header. I want to implement something similar for an arbitrary binary blob, programmed in Javascript.

TreyK

Posted 2014-01-22T02:56:10.017

Reputation: 2 179

Answers

1

whether it's only JPG files that can handle extra data at the end

Any file format that declare the size of its content could be appended with random data and still parsed correctly by a specification compliant apps. JPG files consist of multiple segments, with dynamic-length segments declaring their length in the beginning. Thus any random data appended in the end should work, since the app reading them shouldn't even access those appended data. Same thing with PNGs (each chunks declared their length in the beginning). This won't work on MP3s unfortunately.

However, this would only work on compliant apps. Some apps may take shortcuts for reducing memory or speeding up their reading, which could make the image distorted. The apps themselves could fail on loading large files due their own/framework/device memory constraint.

Martheen Cahya Paulo

Posted 2014-01-22T02:56:10.017

Reputation: 1 347