carlos / platform Public

demobuild: name the NUL tar typeflag instead of tar.TypeRegA

archive/tar.TypeRegA is deprecated since Go 1.11 in favour of TypeReg,
but plainTar reads raw records before archive/tar converts the flag, so
it still has to recognise the NUL byte itself. A local constant keeps
the same value and the same check.

TestDemoSourceAcceptsNULTypeflag passes on the old code and fails when
the NUL byte is refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 433776efa375e5a8807882fe3dbb8bba5c9d64b9 parent d22791e
2 files changed, +17 −1
  • internal/demobuild/source.go +5 −1
  • internal/demobuild/source_test.go +12 −0
diff --git a/internal/demobuild/source.go b/internal/demobuild/source.go
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.
diff --git a/internal/demobuild/source_test.go b/internal/demobuild/source_test.go
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