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

Fix LZO decompression #28

Merged
merged 6 commits into from
Jul 5, 2023
Merged

Fix LZO decompression #28

merged 6 commits into from
Jul 5, 2023

Conversation

Schamper
Copy link
Member

@Schamper Schamper commented Jun 20, 2023

@Schamper Schamper requested a review from pyrco June 20, 2023 13:41
@Schamper Schamper self-assigned this Jun 20, 2023
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #28 (8351190) into main (1e6dcd2) will increase coverage by 0.03%.
The diff coverage is 86.00%.

@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   84.97%   85.00%   +0.03%     
==========================================
  Files          16       16              
  Lines        1118     1107      -11     
==========================================
- Hits          950      941       -9     
+ Misses        168      166       -2     
Flag Coverage Δ
unittests 85.00% <86.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
dissect/util/compression/lzo.py 82.85% <86.00%> (+0.14%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Schamper Schamper requested a review from Miauwkeru June 22, 2023 13:16
dissect/util/compression/lzo.py Outdated Show resolved Hide resolved
dissect/util/compression/lzo.py Show resolved Hide resolved
dissect/util/compression/lzo.py Outdated Show resolved Hide resolved
dissect/util/compression/lzo.py Outdated Show resolved Hide resolved
@@ -58,54 +46,49 @@ def decompress(src: Union[bytes, BinaryIO], header: bool = True, buflen: int = -
val = src.read(1)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't something like this add a bit more readability to the whole thing?

LZO_VERSION_1 = 0x10
LZO_VERSION_2 = 0x11


def _determine_lzo_version(src: io.BytesIO, dst: bytearray) -> int:
    """Determines the LZO version of the src.

    Returns:
        The next value in LZO Stream
    """
    val = src.read(1)[0]
    if val == LZO_VERSION_1:
        raise ValueError("LZOv1")
    elif val > LZO_VERSION_2:
        # LZO is a stream
        dst += src.read(val - LZO_VERSION_2)
        val = src.read(1)[0]

        if val < LZO_VERSION_1:
            raise ValueError("Invalid LZO stream")
    return val

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe good to add these references.
I looked a bit at making the code more readable, but that is far from trivial. Maybe comment the if statements a bit about which byte encoding is indicated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them as references

Copy link
Contributor

@pyrco pyrco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment

@Schamper Schamper requested review from pyrco and Miauwkeru July 4, 2023 10:32
Copy link
Contributor

@Miauwkeru Miauwkeru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be an idea to add some comments about which instruction encoding is used?
Including the first byte encodings


trailing = 0
if val > 17:
dst += src.read(val - 17)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this need an additional state variable?
As, according to the documentation you provided, state is already assigned at the first byte?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Schamper
Copy link
Member Author

Schamper commented Jul 4, 2023

Would it be an idea to add some comments about which instruction encoding is used?
Including the first byte encodings

You seem to understand the algorithm better than me by now so feel free to make some suggestions 😄

dissect/util/compression/lzo.py Show resolved Hide resolved
dissect/util/compression/lzo.py Show resolved Hide resolved
dissect/util/compression/lzo.py Show resolved Hide resolved
dissect/util/compression/lzo.py Show resolved Hide resolved
dissect/util/compression/lzo.py Show resolved Hide resolved
Schamper and others added 2 commits July 5, 2023 14:35
Co-authored-by: Miauwkeru <Miauwkeru@users.noreply.github.com>
@Schamper Schamper requested a review from Miauwkeru July 5, 2023 12:35
@Schamper Schamper merged commit 931f5ca into main Jul 5, 2023
18 checks passed
@Schamper Schamper deleted the fix-lzo branch July 5, 2023 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash iterating types of inodes
3 participants