AU: Don't use sparse holes as scratch space in the delta generator.
This patch fixes a number of bugs related to handling of sparse holes
in the context of scratch space in the delta diff generator and adds
appropriate unit tests. Most notably:
- Ignore sparse holes for the purposes of ExtentRanges. This prevents
the generator from using sparse holes as scratch.
- Adds two unit tests to catch using sparse holes as scratch in a more
deterministric way.
- Handle correctly sparse holes in
GraphUtils::AppendBlockToExtents. For example, previously, if one
adds block 0 to a single-block kSparseHole extent, the extent would
have been simply extended.
BUG=chromium:238440
TEST=unit tests, trybots
Change-Id: I3fedcc93af319ee741821ad9d1a2a57b7a7d5de2
Reviewed-on: https://gerrit.chromium.org/gerrit/50448
Commit-Queue: Darin Petkov <petkov@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/graph_utils.cc b/graph_utils.cc
index 02b49c3..3e3cc9e 100644
--- a/graph_utils.cc
+++ b/graph_utils.cc
@@ -33,21 +33,17 @@
}
void AppendBlockToExtents(vector<Extent>* extents, uint64_t block) {
+ // First try to extend the last extent in |extents|, if any.
if (!extents->empty()) {
Extent& extent = extents->back();
- if (block == kSparseHole) {
- if (extent.start_block() == kSparseHole) {
- // Extend sparse hole extent
- extent.set_num_blocks(extent.num_blocks() + 1);
- return;
- } else {
- // Create new extent below outer 'if'
- }
- } else if (extent.start_block() + extent.num_blocks() == block) {
+ uint64_t next_block = extent.start_block() == kSparseHole ?
+ kSparseHole : extent.start_block() + extent.num_blocks();
+ if (next_block == block) {
extent.set_num_blocks(extent.num_blocks() + 1);
return;
}
}
+ // If unable to extend the last extent, append a new single-block extent.
Extent new_extent;
new_extent.set_start_block(block);
new_extent.set_num_blocks(1);