Read within bounds of `NSData` object

Summary: This prevents the `isUnbundle` check to read beyond the end of an `NSData` instance by using `getBytes:length:` instead of accessing the underlying buffer directly.

Reviewed By: javache

Differential Revision: D3548874

fbshipit-source-id: 7c93c66cc6abb4a2a321888ab394212f4d14a03e
This commit is contained in:
David Aurelio 2016-07-12 10:11:42 -07:00 committed by Facebook Github Bot 3
parent 0d3c4f8e5e
commit c33084cc94
1 changed files with 3 additions and 2 deletions

View File

@ -730,8 +730,9 @@ static NSData *loadPossiblyBundledApplicationScript(NSData *script, NSURL *sourc
NSError **error)
{
// The RAM bundle has a magic number in the 4 first bytes `(0xFB0BD1E5)`.
uint32_t magicNumber = NSSwapLittleIntToHost(*((uint32_t *)script.bytes));
isRAMBundle = magicNumber == RCTRAMBundleMagicNumber;
uint32_t magicNumber = 0;
[script getBytes:&magicNumber length:sizeof(magicNumber)];
isRAMBundle = NSSwapLittleIntToHost(magicNumber) == RCTRAMBundleMagicNumber;
if (isRAMBundle) {
[performanceLogger markStartForTag:RCTPLRAMBundleLoad];
script = loadRAMBundle(sourceURL, error, randomAccessBundle);