Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions XADStuffItXIronHandle.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "StuffItXUtilities.h"
#import "CarrylessRangeCoder.h"
#import "BWT.h"
#import <limits.h>



Expand Down Expand Up @@ -93,12 +94,21 @@ -(int)produceBlockAtOffset:(off_t)pos

if(CSInputNextBitLE(input)==1) return -1;

unsigned int blocksize=(unsigned int)CSInputNextSitxP2(input);
uint64_t rawblocksize=CSInputNextSitxP2(input);
// Values above INT_MAX overflow when cast to int later (e.g. decodeBlockWithLength:).
if(rawblocksize>INT_MAX) [XADException raiseIllegalDataException];
unsigned int blocksize=(unsigned int)rawblocksize;
Comment thread
alek-prykhodko marked this conversation as resolved.
Comment thread
alek-prykhodko marked this conversation as resolved.

if(blocksize>currsize)
{
size_t allocsize;
bool allocOverflowed=__builtin_mul_overflow((size_t)blocksize,(size_t)6,&allocsize);
if(allocOverflowed)
{
[XADException raiseIllegalDataException];
}
free(block);
block=malloc(blocksize*6);
block=malloc(allocsize);
if(!block) [XADException raiseOutOfMemoryException];
sorted=block+blocksize;
table=(uint32_t *)(block+2*blocksize);
Expand Down
Loading