Граф коммитов

92 Коммитов

Автор SHA1 Сообщение Дата
Samuel Giddins e33336cb37 [ruby/zlib] Avoid allocating intermediary strings when read/readpartial are passed an outbuf
This accounts for a significant number of string allocations when reading rubygems, but we can avoid that in many places by only copying into the outbuf when present

https://github.com/ruby/zlib/commit/d25ef406c1
2024-05-14 21:44:34 +00:00
Nobuyoshi Nakada 2b11bcb84e [ruby/zlib] Clear temporary directory
https://github.com/ruby/zlib/commit/1bed54dcf7
2024-04-20 10:53:41 +00:00
Martin Emde 9f8f32bf9f [ruby/zlib] In Zlib::GzipReader#eof? check if we're actually at eof
Only consider it eof if we read ahead and something fills the buf.
If not, we may only have empty blocks and the footer.

Fixes https://github.com/ruby/zlib/pull/56

https://github.com/ruby/zlib/commit/437bea8003
2024-02-22 06:42:06 +00:00
Jun Aruga 7278747d08 [ruby/zlib] Revert "Workaround: Fix test failures on Ubuntu jammy s390x."
This reverts commit https://github.com/ruby/zlib/commit/9f3b9c470c05 because we will
fix the issue on alternative way.

https://github.com/ruby/zlib/commit/3dfe3f9110
2023-09-29 16:14:29 +00:00
Jun Aruga 295862e22a [ruby/zlib] Workaround: Fix test failures on Ubuntu jammy s390x.
This commit fixes the test failures on the zlib in Ubuntu jammy s390x.

According to the <https://packages.ubuntu.com/jammy-updates/zlib1g> -
`zlib_1.2.11.dfsg-2ubuntu9.2.debian.tar.xz`,
the zlib deb package is applying the patch 410.patch (madler/zlib#410), and
configured by `./configure --dfltcc` on Ubuntu jammy s390x. The `--dfltcc`
is to enable the deflate algorithm in hardware.

It produces a different (but still valid) compressed byte stream, and causes
the test failures in ruby/zlib. As a workaround, set the environment variable
`DFLTCC=0` disabling the implementation in zlib on s390x to the failing tests.

Note we need to test in a child Ruby process with `assert_separately` to test
on the `DFLTCC=0` set by the parent Ruby process.

https://github.com/ruby/zlib/commit/9f3b9c470c
2023-09-25 17:59:04 +00:00
Benoit Daloze 50e3b27db7 [ruby/zlib] Add truffleruby-head in CI
* The latest release does not have this fix:
  c77f8bb35d

https://github.com/ruby/zlib/commit/8abc80b994
2023-09-22 07:29:22 +00:00
Sorah Fukumori d2864ca330 [ruby/zlib] Zlib.gunzip should not fail with utf-8 strings
(https://github.com/ruby/zlib/pull/55)

zstream_discard_input was encoding and character-aware when given input is user-provided, so this discards `len` chars instead of `len` bytes.

Also Zlib.gunzip explains in its rdoc that it is equivalent with the following code, but this doesn't fail for UTF-8 String.

```ruby
string = %w[1f8b0800c28000000003cb48cdc9c9070086a6103605000000].pack("H*").force_encoding('UTF-8')
sio = StringIO.new(string)
p gz.read #=> "hello"
gz&.close
p Zlib.gunzip(string) #=> Zlib::DataError
```

Reported and discovered by eagletmt at https://twitter.com/eagletmt/status/1689692467929694209

https://github.com/ruby/zlib/commit/c5e58bc62a
2023-08-10 20:12:21 +00:00
Nobuyoshi Nakada 9d078fe477 [ruby/zlib] Fix the test broken in older versions
https://github.com/ruby/zlib/commit/fc89ff9ef0
2023-01-09 09:58:43 +00:00
Samuel Williams 6fd5d2dc00
Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867) 2022-12-08 18:19:53 +13:00
Nobuyoshi Nakada 1cbdedec89 [ruby/zlib] Mask checksums to lower 32bits
Upper bits affect the result of `crc32` in zlib 1.2.12.

https://github.com/ruby/zlib/commit/9ab6d04af1
2022-04-02 17:01:33 +09:00
Hiroshi SHIBATA 6b87d98011 [ruby/zlib] Use omit instead of skip for test-unit
https://github.com/ruby/zlib/commit/5f23cd3009
2022-01-11 21:35:22 +09:00
Peter Zhu c51b92c18d [ruby/zlib] [Bug #18358] Fix crash in zlib when in progress
When Zlib::Inflate#inflate or Zlib::Deflate#deflate is called
recursively inside the block, a crash can occur because of an
use-after-free bug.

https://github.com/ruby/zlib/commit/50fb8a0338
2021-11-24 23:01:41 +09:00
Hiroshi SHIBATA 940a19e4b3
Use Test::Unit::AssertionFailedError instead of MiniTest::Assertion for test-unit migration 2021-09-06 18:34:15 +09:00
Jeremy Evans b3d62a77d9 [ruby/zlib] Synchronize access to zstream to prevent segfault in multithreaded use
I'm not sure whether this handles all multithreaded use cases,
but this handles the example that crashes almost immediately
and does 10,000,000 total deflates using 100 separate threads.

To prevent the tests from taking forever, the committed test
for this uses only 10,000 deflates across 10 separate threads,
which still causes a segfault in the previous implementation
almost immediately.

Fixes [Bug #17803]

https://github.com/ruby/zlib/commit/4b1023b3f2
2021-07-28 13:40:03 +09:00
Yusuke Endoh ee372aa873 test/zlib/test_zlib.rb: Set binmode to test output file
Seems like the test `TestZlibGzipFile#test_gzip_reader_zcat` fails when
the timestamp has `\n\n`.

https://ci.appveyor.com/project/ruby/ruby/builds/38597932
```
  1) Error:
TestZlibGzipFile#test_gzip_reader_zcat:
Zlib::DataError: invalid distance too far back
    C:/projects/ruby/test/zlib/test_zlib.rb:522:in `initialize'
    C:/projects/ruby/test/zlib/test_zlib.rb:522:in `new'
    C:/projects/ruby/test/zlib/test_zlib.rb:522:in `zcat'
    C:/projects/ruby/test/zlib/test_zlib.rb:522:in `block (2 levels) in test_gzip_reader_zcat'
    C:/projects/ruby/test/zlib/test_zlib.rb:521:in `open'
    C:/projects/ruby/test/zlib/test_zlib.rb:521:in `block in test_gzip_reader_zcat'
    C:/projects/ruby/lib/tempfile.rb:358:in `create'
    C:/projects/ruby/test/zlib/test_zlib.rb:510:in `test_gzip_reader_zcat'
```

The test time is around 2021-04-08 04:40 +0900. Maybe the following time
should trigger the bug.

```
irb(main):001:0> Time.at(1617824266)
=> 2021-04-08 04:37:46 +0900
irb(main):002:0> [1617824266].pack("V")
=> "\n\nn`"
```
2021-04-08 14:26:42 +09:00
Yusuke Endoh 81d52978d0 test/zlib/test_zlib.rb: stop a failure on armv7l
The platform defines a constant File::TMPFILE, but it seems unavailable
(maybe depending on the file system?).

http://rubyci.s3.amazonaws.com/scw-9d6766/ruby-master/log/20210322T171707Z.fail.html.gz

This change adds some rescue cluases to the test, copied from
test/ruby/test_file.rb.
2021-03-23 12:20:58 +09:00
Sorah Fukumori 756e8a2cf3
test_zlib(test_path_tmpfile): fix Zlib instance leak
follow-up: commit cf831f4918
2021-03-17 02:42:31 +09:00
Sorah Fukumori cf831f4918
zlib: fix Gzip{Writer,Reader}.new fails with a O_TMPFILE file 2021-03-17 02:16:27 +09:00
Hiroshi SHIBATA 231f0f6f45 [ruby/zlib] test-unit didn't provide __name__ attribute
https://github.com/ruby/zlib/commit/7d3fc1f325
2021-02-10 12:49:16 +09:00
Nobuyoshi Nakada b4eba8dfee
Prefer block forms to close opened files 2021-02-03 17:34:41 +09:00
Nobuyoshi Nakada d05a268adc
Open gzip file in binary mode 2021-02-03 17:32:41 +09:00
Jeremy Evans 0adc426ca5 [ruby/zlib] Add Zlib::Inflate#inflate :buffer keyword argument
If a buffer keyword argument is given, it is used as the buffer,
instead of creating new strings.  This can result in significantly
lower memory usage during inflation.

Implements #19

https://github.com/ruby/zlib/commit/dac9a9b57d
2020-12-04 19:12:32 +09:00
Jeremy Evans bc63ec57e7 [ruby/zlib] Allow Zlib.crc32 and .adler32 to accept IO instance
This reads from the IO in 8192 byte chunks, so you don't need to
have the entire string in memory.

Fixes #16

https://github.com/ruby/zlib/commit/ba9793c550
2020-12-04 19:12:20 +09:00
Jeremy Evans d52dffd817 [ruby/zlib] Add Zlib::GzipReader.zcat for handling multiple gzip streams in gz file
Most gzip tools support concatenated gz streams in a gz file. This
offers a way to handle such gz files in Ruby.

Fixes [Bug #9790]
Fixes [Bug #11180]
Fixes [Bug #14804]

https://github.com/ruby/zlib/commit/e2ce56de7d
2020-09-14 17:52:20 +09:00
Alan Wu 0aaa15f636 [ruby/zlib] Fix setting mtime to zero in GzipWriter
Before this change, it was not possible to write out zero for the
timestamp part of a Gzip file's header, as calling GzipWriter#mtime with
zero was ignored.

Judging from the docs for `GzipWriter#mtime=`, it should be possible to
indicate that no timestamp is available by calling the method with zero.

https://github.com/ruby/zlib/commit/310be39cac
2019-10-31 22:23:58 +09:00
Jeremy Evans 290903dba0
[ruby/zlib] Remove taint support
Ruby 2.7 deprecates taint and it no longer has an effect.
The lack of taint support should not cause a problem in
previous Ruby versions.

https://github.com/ruby/zlib/commit/21711ed0ce
2019-10-31 15:34:01 +09:00
Nobuyoshi Nakada 1cce430324
Suppress deflateParams() warnings 2019-07-24 22:07:10 +09:00
normal cc9b57a2b4 zlib (gzfile_write_raw): do not resize string after .write call
Apparently, a component of Rails implements a buffering .write
method which keeps the String buffer around and makes it unsafe
for us to clear it after calling .write.

This caused Rack::Deflater to give empty results when enabled.

Fortunately, per r61631 / a55abcc0ca,
this misguided optimization was only worth a small (0.5MB) savings
and we still benefit from the majority of the memory savings in
that change.

Thanks to zunda for the bug report.

[ruby-core:90133] [Bug #15356]

Fixes: r61631 (commit a55abcc0ca)
       ("zlib: reduce garbage on gzip writes (deflate)")

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-07 07:09:31 +00:00
mame 7735e2da11 test/zlib/test_zlib.rb (test_path): enable the accidentally-disabled assertion
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-17 06:38:08 +00:00
nobu 585cbf6535 zlib.c: multiple arguments to write
* ext/zlib/zlib.c (rb_gzwriter_write): accepts multiple arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 07:06:12 +00:00
nobu b268da23d2 zlib.c: memory leak in gunzip
* ext/zlib/zlib.c (zlib_gunzip): clear zstream to fix memory leak.
  [ruby-core:83162] [Bug #13982]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-06 13:41:37 +00:00
naruse 7c9c2bc1dd Zlib::GzipReader#pos underflows after calling #ungetbyte or #ungetc at start of file [Bug #13616]
patched by Andrew Haines <andrew@haines.org.nz> [ruby-core:81488]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-14 09:17:55 +00:00
nobu d70e47dc6b zlib.c: no buf_filled in zstream
* ext/zlib/zlib.c (zstream): manage capacity and size of `buf`
  instead of size and separated member `buf_filled`.  reported by
  Christian Jalio (jalio) at https://hackerone.com/reports/211958

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-01 02:01:38 +00:00
kazu 026ded9384 {ext,test}/zlib: Specify frozen_string_literal: true.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-07 12:49:57 +00:00
nobu 3408e9e3c3 revert r57323
StringIO.new makes the buffer IO.default_external, while
StringIO.new("".dup) makes source encoding which is defaulted to
UTF-8.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-14 09:38:56 +00:00
nobu c8a4b57254 StringIO.new makes a RW buffer
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-14 02:06:22 +00:00
naruse f3d0c2729a suppress warning: attempt to close unfinished zstream; reset forced.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20 16:02:22 +00:00
naruse ba568c0ea3 Zlib.gzip uses kwargs instead of argc [Feature #13020]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-20 16:02:21 +00:00
nobu f46a137746 zlib.c: replace with substring
* ext/zlib/zlib.c (zstream_discard_input): replace with unread
  portion substring, not modifying the input buffer directly.
  [ruby-core:78567] [Bug #13021]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-10 08:26:40 +00:00
naruse 583b6dc33c Zlib.gzip and Zlib.gunzip [Feature #13020]
Encode and Decode gzip data without creating files.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-09 22:45:39 +00:00
odaira 1ec6bb95bc * test/zlib/test_zlib.rb (test_adler32_combine, test_crc32_combine):
Skip two tests on AIX because zconf.h in zlib does not correctly
  recognize _LARGE_FILES in AIX. The problem was already reported
  to zlib, and skip these tests until it is fixed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-04 22:20:56 +00:00
naruse 3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
nobu ae042f21fb use assert_raise
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 02:18:44 +00:00
glass d88957abad * ext/zlib/zlib.c (rb_gzreader_external_encoding):
define GzipReader#external_encoding.
  [Bug #10900]

* test/zlib/test_zlib.rb: test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-10 03:43:22 +00:00
akr b6d5ce7975 * ext/zlib/zlib.c (rb_gzfile_close): Don't raise on double
close for consistent to IO#close.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-08 13:52:51 +00:00
akr 255955585c * io.c (rb_io_close_m): Don't raise when the IO object is closed.
[ruby-core:67444] [Feature #10718]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-15 15:26:03 +00:00
normal 3cee6a22c0 zlib: GzipReader#rewind preserves ZSTREAM_FLAG_GZFILE
* ext/zlib/zlib.c (gzfile_reset): preserve ZSTREAM_FLAG_GZFILE
  [Bug #10101]

* test/zlib/test_zlib.rb (test_rewind): test each_byte

We must preserve the ZSTREAM_FLAG_GZFILE flag to prevent
zstream_detach_buffer from:

a) returning Qnil and breaking out of the `each_byte' loop
b) yielding a large string to each_byte

Note: the test case in bug report takes a long time.  I found this
bug because I noticed the massive time descrepancy between
`each_byte' and `readbyte' loop before this patch.  With this patch,
`each_byte' and `readbyte' both take very long.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-30 23:53:28 +00:00
hsbt f6ae77d97a * test/zlib/test_zlib.rb: remove commented out code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-28 06:57:28 +00:00
hsbt 93156392dd * test/socket/test_addrinfo.rb: remove unused variables.
* test/socket/test_nonblock.rb: ditto.
* test/socket/test_socket.rb: ditto.
* test/socket/test_unix.rb: ditto.
* test/testunit/test_parallel.rb: ditto.
* test/webrick/test_filehandler.rb: ditto.
* test/xmlrpc/test_features.rb: ditto.
* test/zlib/test_zlib.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-18 12:05:09 +00:00
drbrain 9f2f1fcbc8 * ext/zlib/zlib.c (zstream_run): Fix handling of deflate streams that
need a dictionary but are being decompressed by Zlib::Inflate.inflate
  (which has no option to set a dictionary).  Now Zlib::NeedDict is
  raised instead of crashing.  [ruby-trunk - Bug #8829]
* test/zlib/test_zlib.rb (TestZlibInflate):  Test for the above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-28 20:36:21 +00:00