2 files changed,
+17
−1
internal/demobuild/source.go
+5 −1
internal/demobuild/source_test.go
+12 −0
| index bcbfc5927..6dcf9f363 100644 |
| --- a/internal/demobuild/source.go |
| +++ b/internal/demobuild/source.go |
| @@ -237,6 +237,10 @@ func forbiddenFile(name string, isDir bool) bool { |
| return false |
| } |
| |
| +// tarTypeRegNUL is the typeflag old tar writers use for a regular file. |
| +// plainTar reads raw records, before archive/tar turns it into TypeReg. |
| +const tarTypeRegNUL = '\x00' |
| + |
| func plainTar(b []byte) bool { |
| for len(b) >= 512 { |
| h := b[:512] |
| @@ -252,7 +256,7 @@ func plainTar(b []byte) bool { |
| } |
| return true |
| } |
| - if h[156] != tar.TypeReg && h[156] != tar.TypeRegA && h[156] != tar.TypeDir { |
| + if h[156] != tar.TypeReg && h[156] != tarTypeRegNUL && h[156] != tar.TypeDir { |
| return false |
| } |
| // NUL is a terminator in USTAR, never a way to smuggle another name. |
| index 40c072664..f0045386f 100644 |
| --- a/internal/demobuild/source_test.go |
| +++ b/internal/demobuild/source_test.go |
| @@ -194,6 +194,18 @@ func TestDemoSourceLimits(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// TestDemoSourceAcceptsNULTypeflag: old tar writers mark a regular file with |
| +// a NUL typeflag, and the physical record check has to let it through. |
| +func TestDemoSourceAcceptsNULTypeflag(t *testing.T) { |
| + es := starter(t) |
| + offset := len(tarBytes(t, es)) - 1024 |
| + b := tarBytes(t, append(es, archiveEntry{"extra.go", "package main\n", tar.TypeReg})) |
| + b[offset+156] = 0 |
| + fixHeaderChecksum(b[offset:]) |
| + validate(t, gzipBytes(t, b), true) |
| +} |
| + |
| func TestDemoSourceCannotEscapeLock(t *testing.T) { |
| for _, tc := range []struct { |
| kind byte |