diff --git a/src/dataqueue/queue.cc b/src/dataqueue/queue.cc index c3de4eb570beab..64643680903a78 100644 --- a/src/dataqueue/queue.cc +++ b/src/dataqueue/queue.cc @@ -840,7 +840,9 @@ class FdEntry final : public EntryImpl { path_(std::move(path_)), stat_(stat), start_(start), - end_(end) {} + end_(end) { + CHECK_LE(start, end); + } std::shared_ptr get_reader() override { return ReaderImpl::Create(this); @@ -851,7 +853,7 @@ class FdEntry final : public EntryImpl { uint64_t new_start = start_ + start; uint64_t new_end = end_; if (end.has_value()) { - new_end = std::min(end.value(), end_); + new_end = std::min(end.value() + start_, end_); } CHECK(new_start >= start_); diff --git a/test/parallel/test-blob-file-backed.js b/test/parallel/test-blob-file-backed.js index 24560d9215178c..2e143e6936f748 100644 --- a/test/parallel/test-blob-file-backed.js +++ b/test/parallel/test-blob-file-backed.js @@ -86,6 +86,16 @@ writeFileSync(testfile5, ''); const res1 = blob.slice(995, 1005); strictEqual(await res1.text(), data.slice(995, 1005)); + + // Refs: https://github.com/nodejs/node/issues/53908 + for (const res2 of [ + blob.slice(995, 1005).slice(), + blob.slice(995).slice(0, 10), + blob.slice(0, 1005).slice(995), + ]) { + strictEqual(await res2.text(), data.slice(995, 1005)); + } + await unlink(testfile2); })().then(common.mustCall());