Zakir032002 commented on PR #3374:
URL: https://github.com/apache/fory/pull/3374#issuecomment-3943786200
hey @ayush00git , one more thing — ReadBinary and ReadBytes return a direct
slice into
b.data:
v := b.data[b.readerIndex : b.readerIndex+length]
return v
the problem is fill() compacts the buffer in-place:
copy(b.data, b.data[b.readerIndex:])
so if someone reads a []byte field and holds onto that slice, then the next
read triggers a fill() — the compaction just overwrote the bytes they're
still holding. no error, no panic, just wrong data.
in stream mode you probably want to copy before returning instead of
aliasing:
if b.reader != nil {
result := make([]byte, length)
copy(result, b.data[b.readerIndex:b.readerIndex+length])
b.readerIndex += length
return result
}
in-memory path stays as is.
--
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]