3 ms·
A solution would be to reinvent the wheel invented by pixie and others (PDF has a TOC at the end, too, for example (in ascii, because PDF started life as a text
by Someone 5y ago
A solution would be to reinvent the wheel invented by pixie and others (PDF has a TOC at the end, too, for example (in ascii, because PDF started life as a text-based format “postscript without the halting problem”)) introduce a convention that a table of contents gets appended as two files:
- a file named “TOC” with a well-specified format that contains the byte offsets of each file in the archive
- a file named “TOC-offset” with content the 8-byte offset of the “TOC” entry (keeping this separate means the file can be fixed-size. That makes reliably finding it easier)
Preferably, both files also would have some checksum. The TOC itself could have a pointer to the previous TOC. If so, it could be a diff.
Supporting tools could easily check for the presence of a TOC and either overwrite it with new files and wrote a new one, or just append new files and write a new TOC pair.
Attackers could thwart this by creating an archive without a TOC that has a file ending in what looks like a TOC/TOC-offset pair.
An alternative would be to write the TOC-offset file at the start. That’s more robust against such attacks, but requires the ability to overwrite the start of a file.
- chriswarbo 5y agoThere are dangers when allowing one TOC to refer to another, and the ability of offsets to cause self-reference, e.g. see Section 3 of http://www.ieee-security.org/TC/SPW2014/papers/5103a198.PDF http://www.ieee-security.org/TC/SPW2014/papers/5103a198.PDF In general, it's also a good idea to keep data and metadata distinct, to avoid potential conflicts (and hence exploits). In this case having the archive metadata as a file inside the archive seems fraught with dangers. We could avoid this by e.g. having two levels of archive, e.g. the first level contains TOC files and data files (e.g. tar files); the 'payload' files are kept in the data files. That way, there's no way for payload to be interpreted as metadata, or vice versa.