Skip to content

Commit 995ee5a

Browse files
authored
Base32-encode etag values (#1470)
1 parent 04e98e5 commit 995ee5a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pkg/apk/apk/cache.go

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package apk
1616

1717
import (
1818
"context"
19+
"encoding/base32"
1920
"fmt"
2021
"io"
2122
"net/http"
@@ -331,6 +332,11 @@ func etagFromResponse(resp *http.Response) (string, bool) {
331332
}
332333
// When we get etags, they appear to be quoted.
333334
etag := strings.Trim(remoteEtag[0], `"`)
335+
336+
// To ensure these things are safe filenames, base32 encode them.
337+
// (Avoiding base64 due to case sensitive filesystems.)
338+
etag = base32.StdEncoding.EncodeToString([]byte(etag))
339+
334340
return etag, etag != ""
335341
}
336342

pkg/apk/apk/repo_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package apk
1616

1717
import (
1818
"context"
19+
"encoding/base32"
1920
"fmt"
2021
"io/fs"
2122
"net/http"
@@ -192,7 +193,7 @@ func TestGetRepositoryIndexes(t *testing.T) {
192193
require.NoErrorf(t, err, "unable to get indexes")
193194
require.Greater(t, len(indexes), 0, "no indexes found")
194195
// check that the contents are the same
195-
index1, err := os.ReadFile(filepath.Join(repoDir, "APKINDEX", "an-etag.tar.gz"))
196+
index1, err := os.ReadFile(filepath.Join(repoDir, "APKINDEX", base32.StdEncoding.EncodeToString([]byte("an-etag"))+".tar.gz"))
196197
require.NoError(t, err, "unable to read cache index file")
197198
index2, err := os.ReadFile(filepath.Join(testPrimaryPkgDir, indexFilename))
198199
require.NoError(t, err, "unable to read previous index file")

0 commit comments

Comments
 (0)