Test 2mg comment/creator blocks are "valid"

CiderPress checks that these optional areas are actually as long as the header
says they are and discards them if they're not.  This seems like a useful
heuristic.  It happens to be the only one we can perform.  :)
This commit is contained in:
T. Joseph Carter 2017-07-03 05:21:41 -07:00
parent 48ee2057c5
commit 60b9d1f3c6
1 changed files with 17 additions and 0 deletions

17
cppo
View File

@ -930,15 +930,32 @@ class Disk:
self._raw_twoimg = self.image[:hdr.hdr_len]
if hdr.version == 1:
if hdr.hdr_len == 64:
# Extract comment (if it exists and is valid)
if hdr.comment_offset and hdr.comment_len:
self.twoimg_comment = self.image[
hdr.comment_offset
: hdr.comment_offset + hdr.comment_len]
if len(self.twoimg_comment) != hdr.comment_len:
log.warn('invalid 2mg comment: {} bytes '
'(expected {} bytes)'.format(
len(self.twoimg_comment),
hdr.comment_len))
self.twoimg_comment = None
# Extract creator area (if it exists and is valid)
if hdr.creator_offset and hdr.creator_len:
self.twoimg_creator = self.image[
hdr.creator_offset
: hdr.creator_offset + hdr.creator_len]
if len(self.twoimg_creator) != hdr.creator_len:
log.warn('invalid 2mg creator: {} bytes '
'(expected {} bytes)'.format(
len(self.twoimg_creator),
hdr.creator_len))
self.twoimg_creator = None
self.twoimg_locked = bool(hdr.flags & 0x80000000)
self.twoimg = hdr
else:
log.warn('2mg header length: {} (expected 64 '