Fix unbounded allocations when reading untrusted binary data

This commit is contained in:
世界
2026-08-10 13:26:42 +08:00
parent 45ca32dcb9
commit f260e771ea
11 changed files with 151 additions and 90 deletions
+6 -4
View File
@@ -257,14 +257,16 @@ func readString(reader io.ByteReader) (string, error) {
if err != nil {
return "", err
}
buf := make([]byte, length)
for i := range buf {
buf[i], err = reader.ReadByte()
var result []byte
for range length {
var value byte
value, err = reader.ReadByte()
if err != nil {
return "", err
}
result = append(result, value)
}
return string(buf), nil
return string(result), nil
}
func writeString(buffer *bytes.Buffer, value string) {