Forum: Ruby-core [ruby-trunk - Bug #8935][Open] Zlib::GzipWriter.new with block truncates output to 20 corrupted byte

C6fbbf8a1ed8b1970df297f6bfd66a56?d=identicon&s=25 bugmenot123 (DoNot BugMe) (Guest)
on 2013-09-21 17:32
(Received via mailing list)
Issue #8935 has been reported by bugmenot123 (DoNot BugMe).

----------------------------------------
Bug #8935: Zlib::GzipWriter.new with block truncates output to 20
corrupted bytes
https://bugs.ruby-lang.org/issues/8935

Author: bugmenot123 (DoNot BugMe)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
(({
#!/usr/bin/ruby -w

require "zlib"
require "stringio"

input = File.read "/dev/urandom", 200


# corrupted and only 20 bytes long:

out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
puts out1.bytesize, out1.inspect, ""


# good:

writer = Zlib::GzipWriter.new(StringIO.new)
writer.write input
out2 = writer.close.string
puts out2.bytesize, out2.inspect
}))
=end
C6fbbf8a1ed8b1970df297f6bfd66a56?d=identicon&s=25 bugmenot123 (DoNot BugMe) (Guest)
on 2013-09-21 17:33
(Received via mailing list)
Issue #8935 has been updated by bugmenot123 (DoNot BugMe).


Sorry, another try without any formatting:


#!/usr/bin/ruby -w

require "zlib"
require "stringio"

input = File.read "/dev/urandom", 200

# corrupted and only 20 bytes long:

out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
puts out1.bytesize, out1.inspect, ""


# good:

writer = Zlib::GzipWriter.new(StringIO.new)
writer.write input
out2 = writer.close.string
puts out2.bytesize, out2.inspect
----------------------------------------
Bug #8935: Zlib::GzipWriter.new with block truncates output to 20
corrupted bytes
https://bugs.ruby-lang.org/issues/8935#change-41920

Author: bugmenot123 (DoNot BugMe)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
(({
#!/usr/bin/ruby -w

require "zlib"
require "stringio"

input = File.read "/dev/urandom", 200


# corrupted and only 20 bytes long:

out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
puts out1.bytesize, out1.inspect, ""


# good:

writer = Zlib::GzipWriter.new(StringIO.new)
writer.write input
out2 = writer.close.string
puts out2.bytesize, out2.inspect
}))
=end
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-09-21 23:47
(Received via mailing list)
Issue #8935 has been updated by nobu (Nobuyoshi Nakada).

Description updated


----------------------------------------
Bug #8935: Zlib::GzipWriter.new with block truncates output to 20
corrupted bytes
https://bugs.ruby-lang.org/issues/8935#change-41921

Author: bugmenot123 (DoNot BugMe)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
(({Zlib::GzipWriter.new})) with block truncates output to 20 corrupted
bytes.

 #!/usr/bin/ruby -w

 require "zlib"
 require "stringio"

 input = File.read "/dev/urandom", 200


corrupted and only 20 bytes long:

 out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
 puts out1.bytesize, out1.inspect, ""


good:

 writer = Zlib::GzipWriter.new(StringIO.new)
 writer.write input
 out2 = writer.close.string
 puts out2.bytesize, out2.inspect
=end
C6fbbf8a1ed8b1970df297f6bfd66a56?d=identicon&s=25 bugmenot123 (DoNot BugMe) (Guest)
on 2013-09-22 00:26
(Received via mailing list)
Issue #8935 has been updated by bugmenot123 (DoNot BugMe).


Come to think of it, 20 bytes seems like what the gzip header + footer
would take up...
----------------------------------------
Bug #8935: Zlib::GzipWriter.new with block truncates output to 20
corrupted bytes
https://bugs.ruby-lang.org/issues/8935#change-41922

Author: bugmenot123 (DoNot BugMe)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
(({Zlib::GzipWriter.new})) with block truncates output to 20 corrupted
bytes.

 #!/usr/bin/ruby -w

 require "zlib"
 require "stringio"

 input = File.read "/dev/urandom", 200


corrupted and only 20 bytes long:

 out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
 puts out1.bytesize, out1.inspect, ""


good:

 writer = Zlib::GzipWriter.new(StringIO.new)
 writer.write input
 out2 = writer.close.string
 puts out2.bytesize, out2.inspect
=end
B9aafb646d887f93000d9e8a5a214d6c?d=identicon&s=25 windwiny (wind winy) (Guest)
on 2013-09-23 08:01
(Received via mailing list)
Issue #8935 has been updated by windwiny (wind winy).


Every ruby method can be accept a block.

Zlib::GzipWriter.new just return a object, not callback the block,

Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input }.close.string
is equal
Zlib::GzipWriter.new(StringIO.new).close.string


----------------------------------------
Bug #8935: Zlib::GzipWriter.new with block truncates output to 20
corrupted bytes
https://bugs.ruby-lang.org/issues/8935#change-41925

Author: bugmenot123 (DoNot BugMe)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
(({Zlib::GzipWriter.new})) with block truncates output to 20 corrupted
bytes.

 #!/usr/bin/ruby -w

 require "zlib"
 require "stringio"

 input = File.read "/dev/urandom", 200


corrupted and only 20 bytes long:

 out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
 puts out1.bytesize, out1.inspect, ""


good:

 writer = Zlib::GzipWriter.new(StringIO.new)
 writer.write input
 out2 = writer.close.string
 puts out2.bytesize, out2.inspect
=end
C6fbbf8a1ed8b1970df297f6bfd66a56?d=identicon&s=25 bugmenot123 (DoNot BugMe) (Guest)
on 2013-09-23 12:05
(Received via mailing list)
Issue #8935 has been updated by bugmenot123 (DoNot BugMe).


Whoa. Has that always been the case? Cause I'm pretty sure I saw this
code used somewhere else too.

The problem with .open, which definitely takes a block, is that it only
works with file names, not IO objects and thus not StringIO. But it's
not unreasonable to want to transform a string to a gzipped string,
right?
----------------------------------------
Bug #8935: Zlib::GzipWriter.new with block truncates output to 20
corrupted bytes
https://bugs.ruby-lang.org/issues/8935#change-41928

Author: bugmenot123 (DoNot BugMe)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


=begin
(({Zlib::GzipWriter.new})) with block truncates output to 20 corrupted
bytes.

 #!/usr/bin/ruby -w

 require "zlib"
 require "stringio"

 input = File.read "/dev/urandom", 200


corrupted and only 20 bytes long:

 out1 = Zlib::GzipWriter.new(StringIO.new){ |gz| gz.write input
}.close.string
 puts out1.bytesize, out1.inspect, ""


good:

 writer = Zlib::GzipWriter.new(StringIO.new)
 writer.write input
 out2 = writer.close.string
 puts out2.bytesize, out2.inspect
=end
This topic is locked and can not be replied to.