Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Make set hashing robust to bitwise XOR cancellations #20

Merged
merged 1 commit into from
Nov 22, 2020

Commits on Jan 14, 2019

  1. Make set hashing robust to bitwise XOR cancellations

    The way sets (maps, structs, slices with the "set" tag) are hashed
    relies on an XOR to mix the hashes of their elements. This allows
    multiple independent items to interfere with each other through XOR
    operations. For example, consider a "set" slice with the following two
    structs:
    
    [
      {Key: "a", Value: "v1"},
      {Key: "a", Value: "v2"}
    ]
    
    Changing both keys from "a" to "b" will not change the hash value of the
    overall object, since in either case the two keys will cancel out under
    XOR arithmetic.
    
    This change fixes the problem by adding a step after every set of
    unordered hash operations that "hardens" the result by applying another
    hash. It will prevent components of one unordered hashing operation (for
    example, `Key: "a"` above) from interacting with the same data
    encountered later in a different context.
    
    Note that this changes hashes produced by the package for given inputs.
    
    Closes: mitchellh#18
    Aaron Lehmann committed Jan 14, 2019
    Configuration menu
    Copy the full SHA
    efa4282 View commit details
    Browse the repository at this point in the history