Skip to content

Raise ArgumentError for a zero limit in GzipReader#each_line and #readlines - #174

Open
segiddins wants to merge 1 commit into
ruby:masterfrom
segiddins:segiddins/gzreader-each-line-zero-limit
Open

segiddins wants to merge 1 commit into
ruby:masterfrom
segiddins:segiddins/gzreader-each-line-zero-limit

Conversation

@segiddins

Copy link
Copy Markdown
Contributor

GzipReader#gets(0) returns "" without consuming anything, as IO#gets(0) does, so each_line(0) and readlines(0) never reached the end of the stream and allocated an empty string per iteration until the process ran out of memory. IO#each_line and IO#readlines reject a zero limit for that reason.

Zlib::GzipReader.new(StringIO.new(Zlib.gzip("ab\ncd\n"))).readlines(0)
# expected: ArgumentError
# actual:   never returns

…dlines

GzipReader#gets(0) returns "" without consuming anything, as IO#gets(0) does, so each_line(0) and readlines(0) never reached the end of the stream and allocated an empty string per iteration until the process ran out of memory. IO#each_line and IO#readlines reject a zero limit for that reason.

```ruby
Zlib::GzipReader.new(StringIO.new(Zlib.gzip("ab\ncd\n"))).readlines(0)
# expected: ArgumentError
# actual:   never returns
```

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant