Commit graph

11 commits

Author SHA1 Message Date
Valerie Snyder
8e1fb0009b
Tests: clamscan --fips-limits for CVD loading
Add test to ensure CVD loading fails with --fips-limits flag unless you
provide the .cvd.sign file.

Also provide .sign files in freshclam tests because they'll be needed to
pass if building in a fips-enabled environment.
2025-08-14 22:40:45 -04:00
Valerie Snyder
0cc5d75093
ZIP: Fix infinite loop + significant code cleanup
An infinite loop may occur when scanning some malformed ZIP files.

I introduced this issue in 96c00b6d80
with this line:

```c
// decrement coff by 1 to account for the increment at the end of the loop
coff -= 1;
```

The problem is that the function may return 0, which should
indicate that there are no more files. The result was that
`coff` would stay the same and the loop would repeat.

This issue is in 1.5 development and affects the 1.5.0 beta but
does not affect any production versions.

Fixes: https://github.com/Cisco-Talos/clamav/issues/1534

Special thanks to Sophie0x2E for an initial fix, proposed in
https://github.com/Cisco-Talos/clamav/pull/1539
In review, I was uncomfortable with other existing code and
decided to to a more significant overhaul of the error handling
in the ZIP module.

In addition to cleanup, this commit has some functional changes:

- When parsing a central directory file header inside of
  `parse_central_directory_file_header()`, it will now fail out if the
  "extra length" or "comment length" fields would exceced the length of
  the archive. That doesn't mean the associated local file header won't
  be parsed later, but it won't use the central directory file header
  to find it. Instead, the ZIP module will have to find the local file
  header by searching for extra records not listed in the central directory.

  This change was mostly to tidy up complex error handling.

- Add two FTM new signatures to identify split ZIP archives.

  This signature identifies the first segment (first file) in a split or
  spanned ZIP archive. It may also be found on a single-segment "split"
  archive, depending on the ZIP archiver.
  ```
  0:0:504b0708504b0304:ZIP (First segment split/spanned):CL_TYPE_ANY:CL_TYPE_ZIP
  ```

  Practically speaking, this new signature makes it so ClamAV identifies
  the file as a ZIP right away without having to rely on SFX_ZIP detection.
  Extraction is then handled by the ZIP `cli_unzip` function rather than
  extracting each with `cli_unzip_single` which handles SFX_ZIP entries.

  Note: ClamAV isn't capable of finding additional files on disk to support
  handling the additional segments. So it doesn't make any difference with
  handling those other files.

  This signature is for single-segment split/spanned archives, depending
  on the ZIP archiver.
  ```
  0:0:504b0303504b0304:ZIP (Single-segment split/spanned):CL_TYPE_ANY:CL_TYPE_ZIP
  ```
  Like the first one, this also means we won't rely on SFX_ZIP detection
  and will treat this files as regular ZIPs.

- Added a test file to verify that ClamAV can extract a single-file
  "split" ZIP.

- Added a clamscan test with test files to verify that scanning a split
  archive across two segments correctly extracts the properly formed zip
  file entries. Sadly, we can't join the segments to extract everything.
2025-08-11 18:14:19 -04:00
Val Snyder
7ff29b8c37
Bump copyright dates for 2025 2025-02-14 10:24:30 -05:00
Micah Snyder
9cb28e51e6 Bump copyright dates for 2024 2024-01-22 11:27:17 -05:00
Micah Snyder
42e4c85a02 Tests: Verify that option to disable onenote parser works 2023-12-11 15:18:41 -05:00
Micah Snyder
e4ac4b646a Test: Add test to verify ISO properly extracted w/ empty Joliet tree
Test files created with pycdlib and contain the ClamAV logo.png file.
2023-08-02 22:35:34 -07:00
Micah Snyder
66fd30c80d Test: Check that a trusting a cert won't trust whole archive
This test scans a ZIP containing:
1. An executable signed with a trusted certificate
2. A file that will alert because of a signature match

The goal is to verify that the scan isn't terminated early and that
the entire archive isn't trusted simply because the inner executable is
trusted.
That is, that the "CL_VERIFIED" status does not propagate up out of the
magic_scan of a specific layer.
2023-02-23 14:04:36 -08:00
Micah Snyder
6eebecc303 Bump copyright for 2023 2023-02-12 11:20:22 -08:00
Micah Snyder
bed65c96c0 Update cert trust test after fix, and add new test
The PE cert test can be enabled now that the cert trust feature is
fixed. In so doing I found an issue with it -- it was also using the
block-certificate signature, which overrides the trust-certificate
signatures. This made me realize that we should also have a test to make
sure the block-cert signatures take predence over the trust-cert sigs.

I fixed the original sig and added this second test case.
2022-10-21 17:21:19 -07:00
Micah Snyder
798587c6b3 Tests: add pe-allmatch test set
Adds a test set authored by Andrew Williams that validates correct
allmatch behavior using as many features as possible to alert on a
test.exe program. Source for building the test.exe program is provided,
for those who are curious what it is and what it does, or in case it
needs to be re-built for some reason.

In addition to adding a test that verifies each of the sigs that should
alert, do alert, this adds a test to verify that if an authenticode
trust signature is added, none of the signatures alert.  That test is
presently failing (expected failure, so the tests all pass) and should
be updated when the certificate verification bug is fixed.
2022-10-19 13:13:57 -07:00
Micah Snyder
d938bd9ff9 Tests: break out clamscan tests into separate files
The `clamscan_test.py` file is getting way too long.
Created a new `unit_tests/clamscan` directory and separated all tests
into separate test files.

I also fixed an issue with the clamscan `ign2` test:
The `ign2` test wasn't written correctly and was actually testing
detection despite using the `-d` parameter to try to ignore a signature.
There is a minor bug where `ign2` files may be loaded after other files
when using the `-d` option. It is only guaranteed to be loaded first if
you load all the sigs from the same directory. I fixed the test.
In the future, we should make it so all database files are sorted in a
list before load time regardless of where they're sourced from.
2022-10-19 13:13:57 -07:00