Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refuse uploading too big .zip files #1049

Merged
merged 1 commit into from
Oct 25, 2017
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
10 changes: 9 additions & 1 deletion libcodechecker/libhandlers/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
from libcodechecker.libclient import client as libclient
from libcodechecker.logger import add_verbose_arguments
from libcodechecker.logger import LoggerFactory
from libcodechecker.util import sizeof_fmt
from libcodechecker.util import split_product_url


LOG = LoggerFactory.get_new_logger('STORE')
MAX_UPLOAD_SIZE = 1 * 1024 * 1024 * 1024 # 1GiB


def full_traceback(func):
Expand Down Expand Up @@ -206,7 +208,7 @@ def collect_file_hashes_from_plist(plist_file):
except Exception as ex:
LOG.error('Parsing the plist failed: ' + str(ex))

with zipfile.ZipFile(zip_file, 'a') as zipf:
with zipfile.ZipFile(zip_file, 'a', allowZip64=True) as zipf:
for input_path in inputs:
input_path = os.path.abspath(input_path)

Expand Down Expand Up @@ -315,6 +317,12 @@ def main(args):

try:
assemble_zip(args.input, zip_file, client)

if os.stat(zip_file).st_size > MAX_UPLOAD_SIZE:
LOG.error("The result list to upload is too big (max: {})."
.format(sizeof_fmt(MAX_UPLOAD_SIZE)))
sys.exit(1)

with open(zip_file, 'rb') as zf:
b64zip = base64.b64encode(zf.read())

Expand Down
2 changes: 1 addition & 1 deletion libcodechecker/server/api/report_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def unzip(b64zip):
with open(zip_file, 'wb') as zip_f:
zip_f.write(zlib.decompress(base64.b64decode(b64zip)))

with zipfile.ZipFile(zip_file, 'r') as zipf:
with zipfile.ZipFile(zip_file, 'r', allowZip64=True) as zipf:
try:
zipf.extractall(temp_dir)
except:
Expand Down
13 changes: 13 additions & 0 deletions libcodechecker/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,16 @@ def arg_match(options, args):
continue

return matched_args


def sizeof_fmt(num, suffix='B'):
"""
Pretty print storage units.
Source: https://stackoverflow.com/questions/1094841/
reusable-library-to-get-human-readable-version-of-file-size
"""
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)