Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,7 @@ struct gzfile {
#define GZFILE_FLAG_SYNC ZSTREAM_FLAG_UNUSED
#define GZFILE_FLAG_HEADER_FINISHED (ZSTREAM_FLAG_UNUSED << 1)
#define GZFILE_FLAG_FOOTER_FINISHED (ZSTREAM_FLAG_UNUSED << 2)
#define GZFILE_FLAG_MTIME_IS_SET (ZSTREAM_FLAG_UNUSED << 3)

#define GZFILE_IS_FINISHED(gz) \
(ZSTREAM_IS_FINISHED(&(gz)->z) && ZSTREAM_BUF_FILLED(&(gz)->z) == 0)
Expand Down Expand Up @@ -2516,7 +2517,7 @@ gzfile_make_header(struct gzfile *gz)
if (!NIL_P(gz->comment)) {
flags |= GZ_FLAG_COMMENT;
}
if (gz->mtime == 0) {
if (!(gz->z.flags & GZFILE_FLAG_MTIME_IS_SET)) {
gz->mtime = time(0);
}

Expand Down Expand Up @@ -3246,6 +3247,7 @@ rb_gzfile_set_mtime(VALUE obj, VALUE mtime)

val = rb_Integer(mtime);
gz->mtime = NUM2UINT(val);
gz->z.flags |= GZFILE_FLAG_MTIME_IS_SET;

return mtime;
}
Expand Down
11 changes: 11 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@ def test_mtime
}
end

def test_zero_mtime
sio = StringIO.new
gz = Zlib::GzipWriter.new(sio)
gz.mtime = 0
gz.write("Hi")
gz.close
reading_io = StringIO.new(sio.string)
reader = Zlib::GzipReader.new(reading_io)
assert_equal(0, reader.mtime.to_i)
end

def test_level
Tempfile.create("test_zlib_gzip_file_level") {|t|
t.close
Expand Down