chaokunyang commented on code in PR #3293:
URL: https://github.com/apache/fory/pull/3293#discussion_r2769067604
##########
go/fory/string.go:
##########
@@ -84,9 +84,13 @@ func readUTF16LE(buf *ByteBuffer, byteCount int, err *Error)
string {
data := buf.ReadBinary(byteCount, err)
// Reconstruct UTF-16 code units
+ // Note: byteCount should always be even for valid UTF-16, but handle
odd counts
+ // gracefully to avoid index out of range panics from malformed data.
charCount := byteCount / 2
u16s := make([]uint16, charCount)
- for i := 0; i < byteCount; i += 2 {
+ // Only iterate up to the last complete pair (round down to even
boundary)
+ evenByteCount := byteCount &^ 1
Review Comment:
Could you chaneg to set an error on `err *Error` instead of ignore that last
byte?
##########
go/fory/string.go:
##########
@@ -84,9 +84,13 @@ func readUTF16LE(buf *ByteBuffer, byteCount int, err *Error)
string {
data := buf.ReadBinary(byteCount, err)
// Reconstruct UTF-16 code units
+ // Note: byteCount should always be even for valid UTF-16, but handle
odd counts
+ // gracefully to avoid index out of range panics from malformed data.
charCount := byteCount / 2
u16s := make([]uint16, charCount)
- for i := 0; i < byteCount; i += 2 {
+ // Only iterate up to the last complete pair (round down to even
boundary)
+ evenByteCount := byteCount &^ 1
Review Comment:
Could you change to set an error on `err *Error` instead of ignore that last
byte?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]