From 45177dade2a1e07f51a87bb4d23d07dbd0cddb7a Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Wed, 15 Jan 2025 13:03:48 -0600 Subject: [PATCH] contenthash: clear ModeIrregular before sending to archive/tar Clears ModeIrregular from the checksum generation. This may be sent by the client when the version of Go used is post Go 1.23. The behavior of `os.Stat` was modified in Go 1.23 to set `ModeIrregular` on reparse points in Windows. This clears `ModeIrregular` when any mode is set which was the previous behavior of `os.Stat`. Signed-off-by: Jonathan A. Sternberg --- cache/contenthash/filehash.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cache/contenthash/filehash.go b/cache/contenthash/filehash.go index 98fc93e13..2b53fb2ec 100644 --- a/cache/contenthash/filehash.go +++ b/cache/contenthash/filehash.go @@ -41,6 +41,15 @@ func NewFileHash(path string, fi os.FileInfo) (hash.Hash, error) { } func NewFromStat(stat *fstypes.Stat) (hash.Hash, error) { + // Clear the irregular file bit if this is some kind of special + // file. Pre-Go 1.23 behavior would only add the irregular file + // bit to regular files with non-handled reparse points. + // Current versions of Go now apply them to directories too. + // archive/tar.FileInfoHeader does not handle the irregular bit. + if stat.Mode&uint32(os.ModeType&^os.ModeIrregular) != 0 { + stat.Mode &^= uint32(os.ModeIrregular) + } + // Clear the socket bit since archive/tar.FileInfoHeader does not handle it stat.Mode &^= uint32(os.ModeSocket)