Skip to content

Commit ebce39e

Browse files
Paschalis TsiliasJay Conrod
Paschalis Tsilias
authored and
Jay Conrod
committed
txtar/archive: ignore invalid file separators
In case the file separator line does not define a filename, it should be ignored. Updates golang/go#47193 Change-Id: I3a0fee584c0f6b2b41814e79d20884d6468a3b76 Reviewed-on: https://go-review.googlesource.com/c/tools/+/336932 Run-TryBot: Jay Conrod <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Trust: Jay Conrod <[email protected]> Trust: Michael Matloob <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 4fe0d6c commit ebce39e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

txtar/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func isMarker(data []byte) (name string, after []byte) {
121121
if i := bytes.IndexByte(data, '\n'); i >= 0 {
122122
data, after = data[:i], data[i+1:]
123123
}
124-
if !bytes.HasSuffix(data, markerEnd) {
124+
if !(bytes.HasSuffix(data, markerEnd) && len(data) >= len(marker)+len(markerEnd)) {
125125
return "", nil
126126
}
127127
return strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after

txtar/archive_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ More file 1 text.
2929
File 2 text.
3030
-- empty --
3131
-- noNL --
32-
hello world`,
32+
hello world
33+
-- empty filename line --
34+
some content
35+
-- --`,
3336
parsed: &Archive{
3437
Comment: []byte("comment1\ncomment2\n"),
3538
Files: []File{
3639
{"file1", []byte("File 1 text.\n-- foo ---\nMore file 1 text.\n")},
3740
{"file 2", []byte("File 2 text.\n")},
3841
{"empty", []byte{}},
3942
{"noNL", []byte("hello world\n")},
43+
{"empty filename line", []byte("some content\n-- --\n")},
4044
},
4145
},
4246
},

0 commit comments

Comments
 (0)