Jens Geyer created THRIFT-6254:
----------------------------------
Summary: OCaml: TFramedTransport#read returns data from the
previous frame after refilling
Key: THRIFT-6254
URL: https://issues.apache.org/jira/browse/THRIFT-6254
Project: Thrift
Issue Type: Bug
Components: OCaml - Library
Reporter: Jens Geyer
{{lib/ocaml/src/TFramedTransport.ml}}, {{method read}} (lines 73-85):
{code}
method read buf off len =
match read_buf with
| Some frame ->
let i = self#read_from_frame frame buf off len in
if i > 0
then i
else begin
self#read_frame;
self#read_from_frame frame buf off len
end
| None ->
self#read_frame;
self#read buf off len
{code}
{{read_frame}} reads the next frame and rebinds the instance variable
{{read_buf}} to a new buffer. The call after it still passes {{frame}}, which
was bound from the *old* {{read_buf}} when the match was entered, so the bytes
handed back come from the frame that has just been exhausted rather than from
the one just read. {{read_buf_offset}} is reset to 0 by {{read_frame}}, so the
exhausted frame is re-read from its start.
The {{None}} branch, three lines below, gets this right: it recurses through
{{self#read}}, which re-reads {{read_buf}}.
h2. Suggested fix
Recurse the same way the {{None}} branch does:
{code}
else begin
self#read_frame;
self#read buf off len
end
{code}
h2. Note
This cannot be verified by execution today, because {{lib/ocaml}} does not
compile on any OCaml release since 4.06 -- see the companion issue on
{{String.create}}.
_Drafted with AI assistance (Claude Opus 5); reviewed and filed by Jens Geyer._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)