Skip to content

Commit

Permalink
Added NSUInteger overflow checks
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Poirier <[email protected]>
  • Loading branch information
Dave Poirier committed Feb 22, 2016
1 parent e0f6c8b commit cad0af4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Base64.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = 'Base64'
s.version = '1.1.1'
s.version = '1.1.2'
s.license = 'Public Domain'
s.summary = 'RFC 4648 Base64 implementation in Objective-C ARC.'
s.homepage = 'https://github.com/ekscrypto/Base64'
s.author = { 'Dave Poirier' => '[email protected]' }
s.source = { :git => 'https://github.com/ekscrypto/Base64.git', :tag => '1.1.1' }
s.source = { :git => 'https://github.com/ekscrypto/Base64.git', :tag => '1.1.2' }
s.source_files = 'Classes', 'Base64/MF_Base64Additions.{h,m}'
s.requires_arc = true
end
4 changes: 3 additions & 1 deletion Base64/MF_Base64Additions.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ +(NSData *)dataFromBase64String:(NSString *)encoding
unsigned char *encodedBytes = (unsigned char *)[encodedData bytes];

NSUInteger encodedLength = [encodedData length];
if( encodedLength >= (NSUIntegerMax - 3) ) return nil; // NSUInteger overflow check
NSUInteger encodedBlocks = (encodedLength+3) >> 2;
NSUInteger expectedDataLength = encodedBlocks * 3;

Expand Down Expand Up @@ -150,7 +151,8 @@ +(NSString *)base64StringFromData:(NSData *)data
// 16 Q 33 h 50 y

NSUInteger dataLength = [data length];
NSUInteger encodedBlocks = (dataLength * 8) / 24;
NSUInteger encodedBlocks = dataLength / 3;
if( (encodedBlocks + 1) >= (NSUIntegerMax / 4) ) return nil; // NSUInteger overflow check
NSUInteger padding = paddingTable[dataLength % 3];
if( padding > 0 ) encodedBlocks++;
NSUInteger encodedLength = encodedBlocks * 4;
Expand Down

0 comments on commit cad0af4

Please sign in to comment.