mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont leak timezone information in gzip comp[ressed streams
This commit is contained in:
parent
447d1c547c
commit
b6cafb08b3
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import os, httplib, hashlib, uuid, time, struct, repr as reprlib
|
import os, httplib, hashlib, uuid, struct, repr as reprlib
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
from io import BytesIO, DEFAULT_BUFFER_SIZE
|
||||||
from itertools import chain, repeat, izip_longest
|
from itertools import chain, repeat, izip_longest
|
||||||
@ -138,16 +138,14 @@ def get_ranges(headervalue, content_length): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# gzip transfer encoding {{{
|
# gzip transfer encoding {{{
|
||||||
def gzip_prefix(mtime=None):
|
def gzip_prefix():
|
||||||
# See http://www.gzip.org/zlib/rfc-gzip.html
|
# See http://www.gzip.org/zlib/rfc-gzip.html
|
||||||
if mtime is None:
|
|
||||||
mtime = time.time()
|
|
||||||
return b''.join((
|
return b''.join((
|
||||||
b'\x1f\x8b', # ID1 and ID2: gzip marker
|
b'\x1f\x8b', # ID1 and ID2: gzip marker
|
||||||
b'\x08', # CM: compression method
|
b'\x08', # CM: compression method
|
||||||
b'\x00', # FLG: none set
|
b'\x00', # FLG: none set
|
||||||
# MTIME: 4 bytes
|
# MTIME: 4 bytes, set to zero so as not to leak timezone information
|
||||||
struct.pack(b"<L", int(mtime) & 0xFFFFFFFF),
|
b'\0\0\0\0',
|
||||||
b'\x02', # XFL: max compression, slowest algo
|
b'\x02', # XFL: max compression, slowest algo
|
||||||
b'\xff', # OS: unknown
|
b'\xff', # OS: unknown
|
||||||
))
|
))
|
||||||
@ -168,7 +166,7 @@ def compress_readable_output(src_file, compress_level=6):
|
|||||||
data = zobj.compress(data)
|
data = zobj.compress(data)
|
||||||
if not prefix_written:
|
if not prefix_written:
|
||||||
prefix_written = True
|
prefix_written = True
|
||||||
data = gzip_prefix(time.time()) + data
|
data = gzip_prefix() + data
|
||||||
yield data
|
yield data
|
||||||
yield zobj.flush() + struct.pack(b"<L", crc) + struct.pack(b"<L", size)
|
yield zobj.flush() + struct.pack(b"<L", crc) + struct.pack(b"<L", size)
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user