Skip to content

Commit 417e91c

Browse files
committed
Properly deal with short page reads in cache reader.
Check if the data read for a page is smaller than a system page, and deal with the consequences properly
1 parent 90a17af commit 417e91c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

reader.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ CacheReader::getPage(Off pageoff) const
157157
} else {
158158
p = std::make_unique<Page>();
159159
}
160-
p->load(*upstream, pageoff);
161-
pages.push_front(std::move(p));
162-
return **pages.begin();
160+
p->load(*upstream, pageoff);
161+
pages.push_front(std::move(p));
162+
return **pages.begin();
163163
}
164164

165165
size_t
@@ -175,6 +175,8 @@ CacheReader::read(Off off, size_t count, char *ptr) const
175175
Off offsetOfPageInFile = off - offsetOfDataInPage;
176176
try {
177177
Page &page = getPage(offsetOfPageInFile);
178+
if (offsetOfDataInPage >= page.len)
179+
break;
178180
size_t chunk = std::min(page.len - offsetOfDataInPage, count);
179181
memcpy(ptr, page.data.data() + offsetOfDataInPage, chunk);
180182
off += chunk;

0 commit comments

Comments
 (0)