Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Unified Diff: src/heap/marking.h

Issue 2799283002: [heap] Fix off-by-one cell read in verification methods (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/marking.h
diff --git a/src/heap/marking.h b/src/heap/marking.h
index 282dcd2f845bd0841bc1242afff089850fe6445f..b20a4d86f149bb7012d648563e47b90613c9fd5b 100644
--- a/src/heap/marking.h
+++ b/src/heap/marking.h
@@ -227,10 +227,16 @@ class Bitmap {
if (cells()[i] != ~0u) return false;
}
matching_mask = (end_index_mask - 1);
- return ((cells()[end_cell_index] & matching_mask) == matching_mask);
+ // Check against a mask of 0 to avoid dereferencing the cell after the
+ // end of the bitmap.
+ return (matching_mask == 0) ||
+ ((cells()[end_cell_index] & matching_mask) == matching_mask);
} else {
matching_mask = end_index_mask - start_index_mask;
- return (cells()[end_cell_index] & matching_mask) == matching_mask;
+ // Check against a mask of 0 to avoid dereferencing the cell after the
+ // end of the bitmap.
+ return (matching_mask == 0) ||
+ (cells()[end_cell_index] & matching_mask) == matching_mask;
}
}
@@ -250,10 +256,14 @@ class Bitmap {
if (cells()[i]) return false;
}
matching_mask = (end_index_mask - 1);
- return !(cells()[end_cell_index] & matching_mask);
+ // Check against a mask of 0 to avoid dereferencing the cell after the
+ // end of the bitmap.
+ return (matching_mask == 0) || !(cells()[end_cell_index] & matching_mask);
} else {
matching_mask = end_index_mask - start_index_mask;
- return !(cells()[end_cell_index] & matching_mask);
+ // Check against a mask of 0 to avoid dereferencing the cell after the
+ // end of the bitmap.
+ return (matching_mask == 0) || !(cells()[end_cell_index] & matching_mask);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698