Skip to content

Commit

Permalink
RN: don't check for or add zero terminator to bundle
Browse files Browse the repository at this point in the history
Summary:
JSI performs the check itself, no need to do it here. Plus, bytecode
bundles must not be zero terminated.

Differential Revision: D61058869
  • Loading branch information
Tzvetan Mikov authored and facebook-github-bot committed Aug 10, 2024
1 parent d3bd425 commit 756feeb
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions packages/react-native/React/CxxBridge/NSDataBigString.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,10 @@

namespace facebook::react {

static NSData *ensureNullTerminated(NSData *source)
{
if (!source || source.length == 0) {
return nil;
}

NSUInteger sourceLength = source.length;
unsigned char lastByte;
[source getBytes:&lastByte range:NSMakeRange(sourceLength - 1, 1)];

// TODO: bundles from the packager should always include a NULL byte
// or we should we relax this requirement and only read as much from the
// buffer as length indicates
if (lastByte == '\0') {
return source;
} else {
NSMutableData *data = [source mutableCopy];
unsigned char nullByte = '\0';
[data appendBytes:&nullByte length:1];
return data;
}
}

NSDataBigString::NSDataBigString(NSData *data)
{
m_data = ensureNullTerminated(data);
m_length = MAX([m_data length], 1) - 1;
m_data = data;
m_length = [m_data length];
}

} // namespace facebook::react

0 comments on commit 756feeb

Please sign in to comment.