From d1c27a6bb8f58a9e03465d145bf60510c59007b4 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 21 Dec 2017 14:39:20 +0000 Subject: [PATCH] fix for large decoded value --- .gitignore | 2 ++ .travis.yml | 1 + Makefile | 9 +++++++++ tests/test_main.py | 14 ++++++++++++++ xdelta3/_xdelta3.c | 2 +- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b7925fd..8db5bbb 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ htmlcov/ /*.txt /*.whl /xdelta3/lib/ +/tests/b1.bin +/tests/b2.bin diff --git a/.travis.yml b/.travis.yml index 3235421..a146288 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ install: - gcc -v #- docker pull $DOCKER_IMAGE - pip freeze +- make download-test-files script: - make test diff --git a/Makefile b/Makefile index 4ba3c2b..a8809d5 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,15 @@ lint: flake8 xdelta3/ tests/ pytest xdelta3 -p no:sugar -q +.PHONY: download-test-files +download-test-files: + curl -sL https://github.com/samuelcolvin/xdelta3-python/files/1579377/files.zip > test_html.zip + echo "52bf4ee680a86afdeed9aad30e7d68fa test_html.zip" > test_html.zip.md5 + md5sum -c test_html.zip.md5 + unzip -o test_html.zip + mv b1.bin b2.bin tests + rm test_html.zip test_html.zip.md5 + .PHONY: test test: install pytest --cov=xdelta3 diff --git a/tests/test_main.py b/tests/test_main.py index ee51af0..d5e3ef7 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,6 +1,7 @@ import base64 import os import string +from pathlib import Path import pytest @@ -64,3 +65,16 @@ def test_readme(): value_two_rebuilt = xdelta3.decode(value_one, delta) assert value_two_rebuilt == value_two + + +def test_large_decode(): + this_dir = Path(__file__).parent + try: + b1 = (this_dir / 'b1.bin').read_bytes() + b2 = (this_dir / 'b2.bin').read_bytes() + except FileNotFoundError as e: + raise RuntimeError('file required for test not found, run `make download-test-files`') from e + + d = xdelta3.encode(b1, b2) + b3 = xdelta3.decode(b1, d) + assert b2 == b3 diff --git a/xdelta3/_xdelta3.c b/xdelta3/_xdelta3.c index 4c032ef..ceb2e54 100644 --- a/xdelta3/_xdelta3.c +++ b/xdelta3/_xdelta3.c @@ -27,7 +27,7 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args) output_buf, &output_size, output_alloc, flags); } else { // output shouldn't be bigger than the original plus the delta, but give a little leeway - output_alloc = input_size + source_size * 11 / 10; + output_alloc = input_size + source_size * 2; output_buf = main_malloc(output_alloc); result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size, output_buf, &output_size, output_alloc, flags);