Skip to content

Commit

Permalink
Merge pull request #251 from miurahr/backport-lzma-bcj-249
Browse files Browse the repository at this point in the history
Backport BCJ filter fix
  • Loading branch information
miurahr authored Oct 4, 2020
2 parents d47cbf0 + eabcd49 commit 32eb53c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Removed
Security
--------

`v0.9.9`_
=========

Fixed
-----

* (backport) Fix BCJ filter issue failing a certain data when LZMA+BCJ compression(#240, #250)

`v0.9.8`_
=========

Expand Down Expand Up @@ -774,7 +782,8 @@ Changed


.. History links
.. _Unreleased: https://github.com/miurahr/py7zr/compare/v0.9.8...HEAD
.. _Unreleased: https://github.com/miurahr/py7zr/compare/v0.9.9...HEAD
.. _v0.9.9: https://github.com/miurahr/py7zr/compare/v0.9.8...v0.9.9
.. _v0.9.8: https://github.com/miurahr/py7zr/compare/v0.9.7...v0.9.8
.. _v0.9.7: https://github.com/miurahr/py7zr/compare/v0.9.6...v0.9.7
.. _v0.9.6: https://github.com/miurahr/py7zr/compare/v0.9.5...v0.9.6
Expand Down
7 changes: 7 additions & 0 deletions py7zr/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def _arm_code(self) -> int:
return i

def _x86_code(self) -> int:
"""
The code algorithm from liblzma/simple/x86.c
It is slightly different from LZMA-SDK's bra86.c
:return: buffer position
"""
size = len(self.buffer)
if size < 5:
return 0
Expand Down Expand Up @@ -429,6 +434,8 @@ def _x86_code(self) -> int:
else:
buffer_pos += 1
self.prev_mask |= 1
if self.buffer[buffer_pos + 3] in [0, 0xff]:
self.prev_mask |= 0x10
self.current_position += buffer_pos
return buffer_pos

Expand Down
Binary file added tests/data/copy_bcj_1.7z
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import pathlib

import pytest

import py7zr

testdata_path = pathlib.Path(os.path.dirname(__file__)).joinpath('data')
os.umask(0o022)


@pytest.mark.files
def test_bcj_file(tmp_path):
with py7zr.SevenZipFile(testdata_path.joinpath('copy_bcj_1.7z').open(mode='rb')) as ar:
ar.extractall(tmp_path)

0 comments on commit 32eb53c

Please sign in to comment.