GeezerVison is showing github.com — src: fix slice of slice of file-backed Blob · nodejs/node@ca68544
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/dataqueue/queue.cc +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -840,7 +840,9 @@ class FdEntry final : public EntryImpl { |
840 | 840 | path_(std::move(path_)), |
841 | 841 | stat_(stat), |
842 | 842 | start_(start), |
843 | | - end_(end) {} |
| 843 | + end_(end) { |
| 844 | + CHECK_LE(start, end); |
| 845 | + } |
844 | 846 |
|
845 | 847 | std::shared_ptr<DataQueue::Reader> get_reader() override { |
846 | 848 | return ReaderImpl::Create(this); |
@@ -851,7 +853,7 @@ class FdEntry final : public EntryImpl { |
851 | 853 | uint64_t new_start = start_ + start; |
852 | 854 | uint64_t new_end = end_; |
853 | 855 | if (end.has_value()) { |
854 | | - new_end = std::min(end.value(), end_); |
| 856 | + new_end = std::min(end.value() + start_, end_); |
855 | 857 | } |
856 | 858 |
|
857 | 859 | CHECK(new_start >= start_); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-blob-file-backed.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,6 +86,16 @@ writeFileSync(testfile5, ''); |
86 | 86 |
|
87 | 87 | const res1 = blob.slice(995, 1005); |
88 | 88 | strictEqual(await res1.text(), data.slice(995, 1005)); |
| 89 | + |
| 90 | + // Refs: https://github.com/nodejs/node/issues/53908 |
| 91 | + for (const res2 of [ |
| 92 | + blob.slice(995, 1005).slice(), |
| 93 | + blob.slice(995).slice(0, 10), |
| 94 | + blob.slice(0, 1005).slice(995), |
| 95 | + ]) { |
| 96 | + strictEqual(await res2.text(), data.slice(995, 1005)); |
| 97 | + } |
| 98 | + |
89 | 99 | await unlink(testfile2); |
90 | 100 | })().then(common.mustCall()); |
91 | 101 |
|
|