Project

General

Profile

Actions

Bug #10961

closed

Zlib corrupts data when receive signal

Added by leiting (Lei Ting) over 7 years ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.0.0-p353 2.2.0
[ruby-core:<unknown>]

Description

When receiving signal on main thread, Zlib::Deflate.deflate will be interrupted in zstream_run_func (zlib.c), thus producing unfinished output buffer.

Zlib::Deflate.deflate will return normally, without error, but the return value will be corrupted buffer and can't be decompressed.

Preferred fix: zstream_run() should check if err is Z_STREAM_END, if not, raise an error instead of return normally.


run zlib.rb to reproduce this problem:

ruby zlib.rb

37028
generating len=1000000000 string...
string length=1000000000
compressing...
^CINT (press Ctrl+C or send a signal to the pid)
zlib.rb:13:in deflate': data error (Zlib::DataError) from zlib.rb:13:in test_string'
from zlib.rb:25:in block in <main>' from zlib.rb:25:in each'
from zlib.rb:25:in `'


Files

zlib.rb (646 Bytes) zlib.rb leiting (Lei Ting), 03/11/2015 08:15 AM
bug10961.rb (312 Bytes) bug10961.rb wanabe (_ wanabe), 03/05/2021 07:47 AM

Updated by jeremyevans0 (Jeremy Evans) almost 3 years ago

  • Status changed from Open to Closed

It appears this was fixed between ruby 2.3 and 2.4:

$ ruby24 /home/jeremy/Downloads/zlib.rb  
62780
generating len=1000000000 string...
string length=1000000000
compressing...
^CINT
decompressing...
true

$ ruby23 /home/jeremy/Downloads/zlib.rb  
78994
generating len=1000000000 string...
string length=1000000000
compressing...
^CINT
/home/jeremy/Downloads/zlib.rb:13:in `deflate': data error (Zlib::DataError)
        from /home/jeremy/Downloads/zlib.rb:13:in `test_string'
        from /home/jeremy/Downloads/zlib.rb:25:in `block in <main>'
        from /home/jeremy/Downloads/zlib.rb:25:in `each'
        from /home/jeremy/Downloads/zlib.rb:25:in `<main>'

Updated by wanabe (_ wanabe) over 1 year ago

It doesn't look like it's fixed yet.
It may be a race condition between processes, or an environmental dependency that prevents it from being reproduced.

$ ruby -v bug10961.rb 
ruby 3.1.0dev (2021-03-05T07:33:29Z master 7715d428f1) [x86_64-linux]
bug10961.rb:15:in `deflate': data error (Zlib::DataError)
        from bug10961.rb:15:in `block in <main>'
        from bug10961.rb:6:in `times'
        from bug10961.rb:6:in `<main>'
Actions #4

Updated by wanabe (_ wanabe) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset git|0c5f8c62766afe4605172800063e63fe36996658.


[ruby/zlib] Resume zstream if available [Bug #10961]

Actions #5

Updated by wanabe (_ wanabe) about 1 year ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
Actions #6

Updated by nagachika (Tomoyuki Chikanaga) 6 months ago

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED

Updated by usa (Usaku NAKAMURA) 6 months ago

  • Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED to 2.6: REQUIRED, 2.7: DONE, 3.0: REQUIRED

ruby_2_7 50a986ca582bf16ed643cab33bad9d3d7ebb815d merged revision(s) 0c5f8c62766afe4605172800063e63fe36996658.

Updated by nagachika (Tomoyuki Chikanaga) 4 months ago

  • Backport changed from 2.6: REQUIRED, 2.7: DONE, 3.0: REQUIRED to 2.6: REQUIRED, 2.7: DONE, 3.0: DONE

ruby_3_0 5c15cecfbfe61f9d46f45c949829c79cb7f162a9 merged revision(s) 0c5f8c62766afe4605172800063e63fe36996658.

Actions

Also available in: Atom PDF