diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2018-01-20 15:11:03 +0100 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-02-07 20:49:58 -0800 |
commit | 8ccd320549efdbab3608ddcbefca62bd69f8b879 (patch) | |
tree | 474e3443fe5ac5097f3921df86e909f07cf8a442 /src/node_file.cc | |
parent | 259f62a8e8d4eac2f067b205abc9264b946d6738 (diff) | |
download | android-node-v8-8ccd320549efdbab3608ddcbefca62bd69f8b879.tar.gz android-node-v8-8ccd320549efdbab3608ddcbefca62bd69f8b879.tar.bz2 android-node-v8-8ccd320549efdbab3608ddcbefca62bd69f8b879.zip |
src: don't abort when package.json is a directory
PR-URL: https://github.com/nodejs/node/pull/18270
Fixes: https://github.com/nodejs/node/issues/8307
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/node_file.cc')
-rw-r--r-- | src/node_file.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index 8f016ccf02..a77dc0a986 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -673,6 +673,12 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) { return; } + std::shared_ptr<void> defer_close(nullptr, [fd, loop] (...) { + uv_fs_t close_req; + CHECK_EQ(0, uv_fs_close(loop, &close_req, fd, nullptr)); + uv_fs_req_cleanup(&close_req); + }); + const size_t kBlockSize = 32 << 10; std::vector<char> chars; int64_t offset = 0; @@ -689,14 +695,12 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) { numchars = uv_fs_read(loop, &read_req, fd, &buf, 1, offset, nullptr); uv_fs_req_cleanup(&read_req); - CHECK_GE(numchars, 0); + if (numchars < 0) + return; + offset += numchars; } while (static_cast<size_t>(numchars) == kBlockSize); - uv_fs_t close_req; - CHECK_EQ(0, uv_fs_close(loop, &close_req, fd, nullptr)); - uv_fs_req_cleanup(&close_req); - size_t start = 0; if (offset >= 3 && 0 == memcmp(&chars[0], "\xEF\xBB\xBF", 3)) { start = 3; // Skip UTF-8 BOM. |