Skip to content

Commit

Permalink
Store marker data in a TreeMap instead of a HashMap.
Browse files Browse the repository at this point in the history
The iteration order of HashMap is non-deterministic and we did not sort the keys before iterating over them, which means that the contents of the marker file were also non-deterministic.

This was broken in unknown commit which inadvertently replaced a TreeMap with a HashMap here.

RELNOTES: None.
PiperOrigin-RevId: 553823566
Change-Id: Id83ac059d28c24b2149c82e85c25307865516116
  • Loading branch information
lberki authored and copybara-github committed Aug 4, 2023
1 parent 066db19 commit 3b6f805
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,15 @@ static String unescape(String str) {
private static class DigestWriter {
private final Path markerPath;
private final Rule rule;
private final Map<String, String> markerData;
// not just Map<> to signal that iteration order must be deterministic
private final TreeMap<String, String> markerData;
private final String ruleKey;

DigestWriter(BlazeDirectories directories, RepositoryName repositoryName, Rule rule) {
ruleKey = computeRuleKey(rule);
markerPath = getMarkerPath(directories, repositoryName.getName());
this.rule = rule;
markerData = Maps.newHashMap();
markerData = Maps.newTreeMap();
}

byte[] writeMarkerFile() throws RepositoryFunctionException {
Expand Down

0 comments on commit 3b6f805

Please sign in to comment.