Skip to content

Commit eaaf0cd

Browse files
authored
fix: sys.read: never read files that contain a null byte (#837)
Signed-off-by: Grant Linville <[email protected]>
1 parent 1d2b70c commit eaaf0cd

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/builtin/builtin.go

+6
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,12 @@ func SysRead(_ context.Context, _ []string, input string, _ chan<- string) (stri
489489
if len(data) == 0 {
490490
return fmt.Sprintf("The file %s has no contents", params.Filename), nil
491491
}
492+
493+
// Assume the file is not text if it contains a null byte
494+
if bytes.IndexByte(data, 0) != -1 {
495+
return fmt.Sprintf("The file %s cannot be read because it is not a plaintext file", params.Filename), nil
496+
}
497+
492498
return string(data), nil
493499
}
494500

0 commit comments

Comments
 (0)