From 691679a7905933a5677c3aa66cd87efe33d86c49 Mon Sep 17 00:00:00 2001 From: Will Holen Date: Tue, 23 Jul 2019 17:39:49 -0700 Subject: [PATCH] Improve error message when registering empty bundles Summary: This change lets `registerBundle(bundleId, file)` throw an exception when the file is empty, improving on the current behavior of an eventual SIGABRT saying "MAP_FAILED: Invalid argument" Reviewed By: ridiculousfish Differential Revision: D16451938 fbshipit-source-id: b8b2d0bfed476319c379122fad59a5bf0a8c813b --- ReactCommon/cxxreact/JSBigString.cpp | 3 +++ ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/ReactCommon/cxxreact/JSBigString.cpp b/ReactCommon/cxxreact/JSBigString.cpp index 325ac35325..57baa28339 100644 --- a/ReactCommon/cxxreact/JSBigString.cpp +++ b/ReactCommon/cxxreact/JSBigString.cpp @@ -110,6 +110,9 @@ static off_t maybeRemap(char *data, size_t size, int fd) { #endif // WITH_FBREMAP const char *JSBigFileString::c_str() const { + if (m_size == 0) { + return ""; + } if (!m_data) { m_data = (const char *) mmap(0, m_size, PROT_READ, MAP_PRIVATE, m_fd, m_mapOff); diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index 351d26fe06..e261dc574b 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -161,6 +161,10 @@ void JSIExecutor::registerBundle( bundleRegistry_->registerBundle(bundleId, bundlePath); } else { auto script = JSBigFileString::fromPath(bundlePath); + if (script->size() == 0) { + throw std::invalid_argument( + "Empty bundle registered with ID " + tag + " from " + bundlePath); + } runtime_->evaluateJavaScript( std::make_unique(std::move(script)), JSExecutor::getSyntheticBundlePath(bundleId, bundlePath));