-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Ruby 4.0: Merge zlib-3.2.3 #16346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruby 4.0: Merge zlib-3.2.3 #16346
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |||||||
| # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 | ||||||||
| #endif | ||||||||
|
|
||||||||
| #define RUBY_ZLIB_VERSION "3.2.2" | ||||||||
| #define RUBY_ZLIB_VERSION "3.2.3" | ||||||||
|
|
||||||||
| #ifndef RB_PASS_CALLED_KEYWORDS | ||||||||
| # define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass) | ||||||||
|
|
@@ -860,9 +860,7 @@ zstream_buffer_ungets(struct zstream *z, const Bytef *b, unsigned long len) | |||||||
| char *bufptr; | ||||||||
| long filled; | ||||||||
|
|
||||||||
| if (NIL_P(z->buf) || (long)rb_str_capacity(z->buf) <= ZSTREAM_BUF_FILLED(z)) { | ||||||||
| zstream_expand_buffer_into(z, len); | ||||||||
| } | ||||||||
| zstream_expand_buffer_into(z, len); | ||||||||
|
|
||||||||
| RSTRING_GETMEM(z->buf, bufptr, filled); | ||||||||
| memmove(bufptr + len, bufptr, filled); | ||||||||
|
|
@@ -1456,7 +1454,6 @@ rb_zstream_finish(VALUE obj) | |||||||
| * call-seq: | ||||||||
| * flush_next_in -> input | ||||||||
| * | ||||||||
|
||||||||
| * | |
| * | |
| * Flushes the input buffer and returns all data currently held in that buffer. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -882,6 +882,25 @@ def test_ungetc_at_start_of_file | |||||||||||||||||||||||||||||||||||||||||||||
| assert_equal(-1, r.pos, "[ruby-core:81488][Bug #13616]") | ||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def test_ungetc_buffer_underflow | ||||||||||||||||||||||||||||||||||||||||||||||
| initial_bufsize = 1024 | ||||||||||||||||||||||||||||||||||||||||||||||
| payload = "A" * initial_bufsize | ||||||||||||||||||||||||||||||||||||||||||||||
| gzip_io = StringIO.new | ||||||||||||||||||||||||||||||||||||||||||||||
| Zlib::GzipWriter.wrap(gzip_io) { |gz| gz.write(payload) } | ||||||||||||||||||||||||||||||||||||||||||||||
| compressed = gzip_io.string | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| reader = Zlib::GzipReader.new(StringIO.new(compressed)) | ||||||||||||||||||||||||||||||||||||||||||||||
| reader.read(1) | ||||||||||||||||||||||||||||||||||||||||||||||
| overflow_bytes = "B" * (initial_bufsize) | ||||||||||||||||||||||||||||||||||||||||||||||
| reader.ungetc(overflow_bytes) | ||||||||||||||||||||||||||||||||||||||||||||||
| data = reader.read(overflow_bytes.bytesize) | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_equal overflow_bytes.bytesize, data.bytesize, data | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_empty data.delete("B"), data | ||||||||||||||||||||||||||||||||||||||||||||||
| data = reader.read() | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_equal initial_bufsize - 1, data.bytesize, data | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_empty data.delete("A"), data | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+893
to
+901
|
||||||||||||||||||||||||||||||||||||||||||||||
| reader.read(1) | |
| overflow_bytes = "B" * (initial_bufsize) | |
| reader.ungetc(overflow_bytes) | |
| data = reader.read(overflow_bytes.bytesize) | |
| assert_equal overflow_bytes.bytesize, data.bytesize, data | |
| assert_empty data.delete("B"), data | |
| data = reader.read() | |
| assert_equal initial_bufsize - 1, data.bytesize, data | |
| assert_empty data.delete("A"), data | |
| begin | |
| reader.read(1) | |
| overflow_bytes = "B" * (initial_bufsize) | |
| reader.ungetc(overflow_bytes) | |
| data = reader.read(overflow_bytes.bytesize) | |
| assert_equal overflow_bytes.bytesize, data.bytesize, data | |
| assert_empty data.delete("B"), data | |
| data = reader.read() | |
| assert_equal initial_bufsize - 1, data.bytesize, data | |
| assert_empty data.delete("A"), data | |
| ensure | |
| reader.close | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zstream_buffer_ungetsnow unconditionally callszstream_expand_buffer_into(z, len). Sincezstream_expand_buffer_intogrows the string bylenwheneveravail_out != len, this will expand the buffer even when there is already enough capacity, causing unnecessary allocations/memory growth for repeated smallungetccalls. Consider expanding only whenrb_str_capacity(z->buf) < ZSTREAM_BUF_FILLED(z) + len(or equivalent), and otherwise just adjustnext_out/avail_outbased on existing free capacity.