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

SlicesAsSets option behaves poorly with duplicate items in the slice #36

@tzneal

Description

@tzneal

If two slices differ only by an item that is repeated in both, it's trivial to construct hash collisions.

package main

import (
	"fmt"

	hashstructure "github.com/mitchellh/hashstructure/v2"
)

func main() {
	// clearly two different lists
	list1 := []string{"a", "b", "c", "e", "e"}
	list2 := []string{"a", "b", "c", "d", "d"}

	// with the same hash
	fmt.Println(hashstructure.Hash(list1, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true}))
	fmt.Println(hashstructure.Hash(list2, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true}))
}

// output
// 12638153115695167423 <nil>
// 12638153115695167423 <nil>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions