Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN: don't check for or add zero terminator to bundle #45966

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
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
Loading