From b1a23914fa428992a31ce5b6c4a35155998e5a47 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Sat, 3 Dec 2016 02:18:59 -0800 Subject: [PATCH] JSIndexedRAMBundle: Don't read null bytes for scripts Summary: `JSIndexedRAMBundle` used to read scripts including the terminating null bytes. That worked on iOS, but not on Android, where we have an ascii-only optimization. This changes that behavior to only read the actual script data excluding the terminal null. Reviewed By: javache Differential Revision: D4265374 fbshipit-source-id: 7e6f943666aee610d79939cef09b103305803c69 --- ReactCommon/cxxreact/JSIndexedRAMBundle.cpp | 9 ++++----- ReactCommon/cxxreact/JSIndexedRAMBundle.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp b/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp index 977fcdd2e..80e528df4 100644 --- a/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp +++ b/ReactCommon/cxxreact/JSIndexedRAMBundle.cpp @@ -33,10 +33,9 @@ JSIndexedRAMBundle::JSIndexedRAMBundle(const char *sourcePath) : reinterpret_cast(m_table.data.get()), m_table.byteLength()); // read the startup code - m_startupCode = - std::make_unique(startupCodeSize); + m_startupCode = std::unique_ptr(new JSBigBufferString{startupCodeSize - 1}); - readBundle(m_startupCode->data(), startupCodeSize); + readBundle(m_startupCode->data(), startupCodeSize - 1); } JSIndexedRAMBundle::Module JSIndexedRAMBundle::getModule(uint32_t moduleId) const { @@ -61,8 +60,8 @@ std::string JSIndexedRAMBundle::getModuleCode(const uint32_t id) const { toString("Error loading module", id, "from RAM Bundle")); } - std::string ret(moduleData->length, '\0'); - readBundle(&ret.front(), length, m_baseOffset + littleEndianToHost(moduleData->offset)); + std::string ret(length - 1, '\0'); + readBundle(&ret.front(), length - 1, m_baseOffset + littleEndianToHost(moduleData->offset)); return ret; } diff --git a/ReactCommon/cxxreact/JSIndexedRAMBundle.h b/ReactCommon/cxxreact/JSIndexedRAMBundle.h index 9562012ef..1a642ea1b 100644 --- a/ReactCommon/cxxreact/JSIndexedRAMBundle.h +++ b/ReactCommon/cxxreact/JSIndexedRAMBundle.h @@ -40,7 +40,7 @@ private: ModuleTable() : numEntries(0) {}; ModuleTable(size_t entries) : numEntries(entries), - data(std::make_unique(numEntries)) {}; + data(std::unique_ptr(new ModuleData[numEntries])) {}; size_t byteLength() const { return numEntries * sizeof(ModuleData); }