1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-18 05:45:45 +02:00

scan: fix length mismatch exception for prealloc extents at EOF

Prealloc extent sizes were taken from the Extent object and did not
take the file size into account.  If a file with a non-4K-aligned
size is preallocated, the resulting dedup fails with an exception
because the size of both ranges of the BeesRangePair do not match.

Limit the size of the replacement hole extent to not extend past the
end of the file.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2018-01-28 01:37:20 -05:00
parent 762f833ab0
commit e74c0a9d80

View File

@ -298,7 +298,9 @@ BeesContext::scan_one_extent(const BeesFileRange &bfr, const Extent &e)
// Prealloc is all zero and we replace it with a hole. // Prealloc is all zero and we replace it with a hole.
// No special handling is required here. Nuke it and move on. // No special handling is required here. Nuke it and move on.
BEESLOGINFO("prealloc extent " << e); BEESLOGINFO("prealloc extent " << e);
BeesFileRange prealloc_bfr(m_ctx->tmpfile()->make_hole(e.size())); // Must not extend past EOF
auto extent_size = min(e.end(), bfr.file_size()) - e.begin();
BeesFileRange prealloc_bfr(m_ctx->tmpfile()->make_hole(extent_size));
BeesRangePair brp(prealloc_bfr, bfr); BeesRangePair brp(prealloc_bfr, bfr);
// Raw dedup here - nothing else to do with this extent, nothing to merge with // Raw dedup here - nothing else to do with this extent, nothing to merge with
if (m_ctx->dedup(brp)) { if (m_ctx->dedup(brp)) {