Skip to content

Commit

Permalink
RN: don't check for or add zero terminator to bundle (#45966)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #45966

JSI performs the check itself, no need to do it here. Plus, bytecode
bundles must not be zero terminated.

## Changelog:

[IOS] [FIXED] - Fixes NSDataBigString length calculation

Reviewed By: realsoelynn

Differential Revision: D61058869

fbshipit-source-id: 15b99ef13f9aebd11ff410d02c21db8e46cc6ac3
  • Loading branch information
Tzvetan Mikov authored and facebook-github-bot committed Aug 22, 2024
1 parent 1f755de commit bb3c51d
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_length = [data length];
m_data = ensureNullTerminated(data);
m_data = data;
m_length = [m_data length];
}

} // namespace facebook::react

0 comments on commit bb3c51d

Please sign in to comment.