Skip to content

Fix byte-limited reads for Enumerator-backed request bodies#275

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/read-io-adapter-byte-read
Open

Fix byte-limited reads for Enumerator-backed request bodies#275
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/read-io-adapter-byte-read

Conversation

@fallintoplace

@fallintoplace fallintoplace commented May 19, 2026

Copy link
Copy Markdown

Summary

  • make Enumerator-backed ReadIOAdapter#read(max_len) return at most max_len bytes
  • use byte-oriented buffering so multibyte strings follow IO#read semantics
  • preserve buffered bytes when an unbounded read follows a partial read
  • match IO behavior for zero-length reads, EOF, negative lengths, and out_string
  • add regression coverage for bounded reads, multibyte data, buffering, and output buffers

Why

This adapter feeds streamed request bodies into IO consumers such as IO.copy_stream. Returning more bytes than requested can break those consumers and corrupt multipart upload boundaries; character-oriented slicing also makes the result depend on string encoding instead of the requested byte count.

Fixes #274.

Test plan

  • bundle exec rake TEST=test/openai/internal/util_test.rb test
  • bundle exec rake lint

@fallintoplace
fallintoplace marked this pull request as ready for review May 19, 2026 17:41
@fallintoplace
fallintoplace requested a review from a team as a code owner May 19, 2026 17:41
@jbeckwith-oai jbeckwith-oai added the generator Touches generated SDK files label Jul 16, 2026
@fallintoplace
fallintoplace force-pushed the fix/read-io-adapter-byte-read branch from 6a6a07c to 9a9d079 Compare July 16, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

generator Touches generated SDK files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReadIOAdapter#read returns too many bytes for Enumerator bodies

2 participants