Skip to content

[Bug]: Suffix Confusion on Evidence Upload #1586

@HolzmanoLagrene

Description

@HolzmanoLagrene

What steps will reproduce the bug?

  1. Normal Api Server Running
  2. When using the /api/evidence/upload endpoint
  3. Most importantly: We upload a CompressedDirectory.

What is the expected behavior?

When uploading a file called filestem.ext1.ext2, in the best case we should always expect the system to correctly split the extensions from the stem of the file and create something like this filestem_timestamp.ext1.ext2.

However as we are not in all cases able to know which extension is the real extension and which one is part of the file name we want to at least preserve all extensions at the end of the name so even if we end up with something like this filestem.ext1_timestamp.ext1.ext2, we would still be good.

What do you see instead?

When we upload a file with name test.E01 we end up with a proper file name test_timestamp.E01. However if we upload test.tar.gz we end up with test.tar_timestamp.gz.

Why is that a problem
ValidateTarFile only accepts the two extensions tgz or tar.gz the extension gz alone will make it throw errors.

Additional information

My suggestion:

Replace these lines:

file_name_without_ext, file_extension = os.path.splitext(file_name)
current_time = datetime.now().strftime(turbinia_config.DATETIME_FORMAT)
new_name = f'{file_name_without_ext}_{current_time}{file_extension}'

with

from pathlib import Path
...
p = Path(file_name)
file_stem = p.stem
full_extension = ''.join(p.suffixes)
current_time = datetime.now().strftime(turbinia_config.DATETIME_FORMAT)
new_name = f"{file_stem}_{current_time}{full_extension}"

As I am the one who tried to fix this in #1459, i consider it my duty to clean my own mess :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions