Commit graph

224 commits

Author SHA1 Message Date
Hiroshi SHIBATA
5a9008516a [ruby/zlib] Bump up v3.2.1
d2e29b23c8
2024-12-13 00:33:58 +00:00
Samuel Williams
f6e6e66870 [ruby/zlib] Add support for safe offload of nogvl code.
(https://github.com/ruby/zlib/pull/89)

a535271862
2024-11-20 21:40:55 +00:00
Samuel Williams
b143fd5bd8 [ruby/zlib] Don't call rb_str_set_len while released the GVL.
(https://github.com/ruby/zlib/pull/88)

* Only release the GVL where necessary.

- Several string manipulation methods were invoked while the GVL was
  released. This is unsafe.
- The mutex protecting multi-threaded access was not covering buffer state
  manipulation, leading to data corruption and out-of-bounds writes.
- Using `rb_str_locktmp` prevents changes to buffer while it's in use.

[Bug #20863]

e445cf3c80
2024-11-20 21:02:16 +00:00
Hiroshi SHIBATA
9c5290138a [ruby/zlib] Bump up v3.2.0
7bb6d982fe
2024-11-12 04:09:58 +00:00
Nobuyoshi Nakada
4755d28f9b [ruby/zlib] Reduce ensure nesting
5a02eac37f
2024-10-24 10:30:37 +00:00
Nobuyoshi Nakada
ae67325dd0 [ruby/zlib] Tell gcc-14 that Qnil is not passed to gzfile_calc_crc
Suppress false positive warnings due to a bug in gcc-14 optimizer.

eb1cf426c2
2024-10-24 10:18:49 +00:00
John Bampton
afacb8ada5
[DOC] Fix spelling 2024-10-12 12:48:10 +00:00
Takashi Kokubun
818e3037ed [ruby/zlib] Bump up 3.1.1
d756bb0a0f
2024-08-31 05:04:30 +00:00
Samuel Giddins
e3e1e53098 [ruby/zlib] Avoid double copying into provided outbuf
07f44b7546
2024-05-14 21:44:34 +00:00
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

d25ef406c1
2024-05-14 21:44:34 +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

437bea8003
2024-02-22 06:42:06 +00:00
Hiroshi SHIBATA
3d5fef7712 [ruby/zlib] Bump up 3.1.0
2561e122ac
2023-11-07 08:50:40 +00:00
KJ Tsanaktsidis
ac4d687656 [ruby/zlib] Fix misdetection of {crc32,alder32}_z in cloudflare zlib fork
We use the Cloudflare fork of zlib
(https://github.com/cloudflare/zlib), which we find gives improved
performance on AWS Graviton ARM instances. That fork does not define
crc32_z and alder32_z functions.

Until two days ago, Ruby's zlib gem worked fine, because cloudflare zlib
_also_ did not define z_size_t, which meant Ruby did not try and use
these functions.

Since a3ba99596d
however, cloudflare zlib _does_ define z_size_t (but NOT crc32_z or
alder32_z). The zlib gem would try and use these nonexistant
functions and not compile.

This patch fixes it by actually specifically detecting the functions
that the gem wants to call, rather than just the presence of the
z_size_t type.

c96e8b9a57
2023-10-26 02:17:54 +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

c5e58bc62a
2023-08-10 20:12:21 +00:00
Hiroshi SHIBATA
3f8dad0463 [ruby/zlib] Bump version to 3.0.0
f1ce5e3e8d
2022-12-05 08:26:21 +00:00
Nobuyoshi Nakada
07acd6006c [ruby/zlib] Use z_size_t version functions
1ce6625fff
2022-04-02 19:34:05 +09:00
Nobuyoshi Nakada
4ee71097a0 [ruby/zlib] Mask checksums to lower 32bits on also IL32 platforms
e1ead85113
2022-04-02 19:23:59 +09:00
Nobuyoshi Nakada
1cbdedec89 [ruby/zlib] Mask checksums to lower 32bits
Upper bits affect the result of `crc32` in zlib 1.2.12.

9ab6d04af1
2022-04-02 17:01:33 +09:00
Mau Magnaguagno
50098f4b61 [ruby/zlib] [DOC] Fix typo in Zlib.adler32_combine
5e8f0b4164
2022-02-22 18:01:53 +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.

50fb8a0338
2021-11-24 23:01:41 +09:00
Peter Zhu
aeae6e2842 [Feature #18290] Remove all usages of rb_gc_force_recycle
This commit removes usages of rb_gc_force_recycle since it is a burden
to maintain and makes changes to the GC difficult.
2021-11-08 14:05:54 -05:00
Hiroshi SHIBATA
b482a516d2 [ruby/zlib] Bump up zlib version to 2.1.1
82e9a636a6
2021-10-19 20:28:57 +09:00
Sutou Kouhei
027a3379d6 [ruby/zlib] Fix a bug that GZipReader#gets may return incomplete line
See also: https://github.com/ruby/csv/issues/117#issuecomment-933289373

How to reproduce with x.csv.gz in the issue comment:

    Zlib::GzipReader.open("x.csv.gz") do |rio|
      rio.gets(nil, 1024)
      while line = rio.gets(nil, 8192)
        raise line unless line.valid_encoding?
      end
    end

Reported by Dimitrij Denissenko. Thanks!!!

b1f182e98f
2021-10-15 15:31:15 +09:00
Hiroshi SHIBATA
6b13448040 [ruby/zlib] Bump up zlib version to 2.1.0
dd593acaee
2021-10-14 16:18:41 +09:00
Hiroshi SHIBATA
db500f05c2 [ruby/zlib] Bump version to v2.0.0
434eba55ae
2021-10-14 16:18:36 +09:00
Nobuyoshi Nakada
d3155e3632 [ruby/zlib] Don't print out warnings when finalizing
44a56d36e7
2021-08-31 23:20:42 +09:00
Nobuyoshi Nakada
31c427511c [ruby/zlib] Revert "Don't print out warnings when freeing."
931aa7a272
2021-08-31 23:20:40 +09:00
Samuel Williams
d19af1675c [ruby/zlib] Don't print out warnings when freeing.
098c50255d
2021-08-31 19:33:38 +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]

4b1023b3f2
2021-07-28 13:40:03 +09:00
Benoit Daloze
fa7a712d46 Fix -Wundef warnings for HAVE_RB_EXT_RACTOR_SAFE
* See [Feature #17752]
2021-05-04 14:56:55 +02:00
Nobuyoshi Nakada
3260602fa3
Adjusted indents [ci skip] 2021-03-17 09:49:17 +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
wanabe
0c5f8c6276 [ruby/zlib] Resume zstream if available [Bug #10961] 2021-03-09 13:19:03 +09:00
Koichi Sasada
b44f7151c7 zlib is ractor-safe 2020-12-18 14:09:32 +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

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

ba9793c550
2020-12-04 19:12:20 +09:00
Jeremy Evans
a60dfff434 [ruby/zlib] Document that gets can return nil when eof? returns false
This behavior differs from File#gets.

Fixes [Bug #13904]

448e41efdd
2020-12-04 19:11:30 +09:00
卜部昌平
43b95bafd5
delete deprecated IO-like methods
This commit deletes
{IO,ARGF,StringIO,Zib::GZipReader}#{bytes,chars,lines,codepoints}, which
have been deprecated since c47c095b97.

Note that String also has those methods.  They are neither depreacted
nor deleted because they are not aliases of counterpart each_something.
2020-12-03 12:47:51 +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]

e2ce56de7d
2020-09-14 17:52:20 +09:00
Hiroshi SHIBATA
b94d06096b [ruby/zlib] Bump version to 1.1.0
5af77c1ee8
2019-11-30 18:21:52 +09:00
Nobuyoshi Nakada
929a4aa722
Adjust a fucntion signature 2019-11-05 02:05:46 +09:00
Nobuyoshi Nakada
63f70eb651 [ruby/zlib] Removed no longer used variables
3e98e4cac3
2019-10-31 22:24:00 +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.

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.

21711ed0ce
2019-10-31 15:34:01 +09:00
Nobuyoshi Nakada
94db8cda9b [ruby/zlib] Fix for older ruby 2.6 or earlier
00ead8cb2c
2019-09-29 18:53:11 +09:00
Jeremy Evans
80b5a0ff2a
Make rb_scan_args handle keywords more similar to Ruby methods (#2460)
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.

This makes the following changes to : handling.

* Treats as **kw, prompting keyword argument separation warnings
  if called with a positional hash.

* Do not look for an option hash if empty keywords are provided.
  For backwards compatibility, treat an empty keyword splat as a empty
  mandatory positional hash argument, but emit a a warning, as this
  behavior will be removed in Ruby 3.  The argument number check
  needs to be moved lower so it can correctly handle an empty
  positional argument being added.

* If the last argument is nil and it is necessary to treat it as an option
  hash in order to make sure all arguments are processed, continue to
  treat the last argument as the option hash. Emit a warning in this case,
  as this behavior will be removed in Ruby 3.

* If splitting the keyword hash into two hashes, issue a warning, as we
  will not be splitting hashes in Ruby 3.

* If the keyword argument is required to fill a mandatory positional
  argument, continue to do so, but emit a warning as this behavior will
  be going away in Ruby 3.

* If keyword arguments are provided and the last argument is not a hash,
  that indicates something wrong. This can happen if a cfunc is calling
  rb_scan_args multiple times, and providing arguments that were not
  passed to it from Ruby.  Callers need to switch to the new
  rb_scan_args_kw function, which allows passing of whether keywords
  were provided.

This commit fixes all warnings caused by the changes above.

It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used.  If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.

In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby.  The last argument may or may not be a hash,
so we can't set keyword argument mode.  However, if it is a
hash, we don't want to warn when treating it as keywords.

In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args.  Also, make
sure not to pass nil in place of an option hash.

Work around Kernel#warn warnings due to problems in the Rubygems
override of the method.  There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.

Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
2019-09-25 11:18:49 -07:00
卜部昌平
703783324c rb_ensure now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_ensure, which also revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平
5c7c2d9951 rb_rescue / rb_rescue2 now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_rescue / rb_rescue2, which revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
normal
23444302d9 introduce rb_nogvl C-API to mark ubf as async-signal-safe
zlib and bignum both contain unblocking functions which are
async-signal-safe and do not require spawning additional
threads.

We can execute those functions directly in signal handlers
without incurring overhead of extra threads, so provide C-API
users the ability to deal with that.  Other C-API users may
have similar need.

This flexible API can supercede existing uses of
rb_thread_call_without_gvl and rb_thread_call_without_gvl2 by
introducing a flags argument to control behavior.

Note: this API is NOT finalized.  It needs approval from other
committers.  I prefer shorter name than previous
rb_thread_call_without_gvl* functions because my eyes requires
big fonts.

[Bug #15499]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-04 13:14:11 +00: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