File tree Expand file tree Collapse file tree 2 files changed +19
-10
lines changed
Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -487,14 +487,16 @@ - (FICImageTableEntry *)_entryDataAtIndex:(NSInteger)index {
487487 void *mappedChunkAddress = [chunk bytes ];
488488 void *mappedEntryAddress = mappedChunkAddress + entryOffsetInChunk;
489489 entryData = [[FICImageTableEntry alloc ] initWithImageTableChunk: chunk bytes: mappedEntryAddress length: _entryLength];
490- [entryData setIndex: index];
491490
492- [_chunkSet addObject: chunk];
491+ if (entryData) {
492+ [entryData setIndex: index];
493+ [_chunkSet addObject: chunk];
493494
494- __weak FICImageTable *weakSelf = self;
495- [entryData executeBlockOnDealloc: ^{
496- [weakSelf _entryWasDeallocatedFromChunk: chunk];
497- }];
495+ __weak FICImageTable *weakSelf = self;
496+ [entryData executeBlockOnDealloc: ^{
497+ [weakSelf _entryWasDeallocatedFromChunk: chunk];
498+ }];
499+ }
498500 }
499501 }
500502
Original file line number Diff line number Diff line change @@ -64,10 +64,17 @@ - (id)initWithImageTableChunk:(FICImageTableChunk *)imageTableChunk bytes:(void
6464 self = [super init ];
6565
6666 if (self != nil ) {
67- _imageTableChunk = imageTableChunk;
68- _bytes = bytes;
69- _length = length;
70- _deallocBlocks = [[NSMutableArray alloc ] init ];
67+ // Safety check
68+ void *entryMax = bytes + length;
69+ void *chunkMax = [imageTableChunk bytes ] + [imageTableChunk length ];
70+ if (entryMax > chunkMax) {
71+ self = nil ;
72+ } else {
73+ _imageTableChunk = imageTableChunk;
74+ _bytes = bytes;
75+ _length = length;
76+ _deallocBlocks = [[NSMutableArray alloc ] init ];
77+ }
7178 }
7279
7380 return self;
You can’t perform that action at this time.
0 commit comments