100 Commits
Author SHA1 Message Date
Victor M. Alvarez a37be989ba fix: harden Authenticode parsing against malformed data
Add numerous null and sequence type checks to prevent crashes when
processing corrupted or unexpected Authenticode signatures and
their nested attributes.

Closes #2242.
2026-08-25 12:54:27 +02:00
Victor M. Alvarez 0cdff36723 fix: validate arena buffer count
Ensure `YR_ARENA` objects are created, loaded, and accessed with a valid number of buffers. This prevents out-of-bounds memory access and improves robustness against corrupted arena data or incorrect API usage.

Closes #2238.
2026-08-25 10:29:10 +02:00
Victor M. Alvarez 84b0e3cc0e Bump version number to 4.5.8. 2026-07-28 09:04:21 +02:00
Victor M. Alvarez 0da50fe5e6 fix: build issues with OpenSSL 4.0. (#2233)
Closes #2232.
2026-07-27 14:14:35 +02:00
Victor M. Alvarez e13acd3d18 Fix memory leak in yr_rules_load_stream. 2026-07-20 10:30:33 +02:00
Victor M. Alvarez a2ff0db010 Add missing yr_le16toh in PE module.
Closes #2231.
2026-07-20 09:40:26 +02:00
Victor M. Alvarez 2aee7f4068 Try to fix build issue in macOS. 2026-06-02 10:34:50 +02:00
Victor M. Alvarez 807ee93b9c Try to fix build error in macOS. 2026-06-02 10:26:52 +02:00
Victor M. Alvarez b1072012cf Upgrade macos version in the build workflow. 2026-06-02 09:53:59 +02:00
Victor M. Alvarez b68c43e7e6 Remove converity.yaml.
`covertity-scan-action` seems to be broken and unmaintained.
2026-06-01 12:52:16 +02:00
Victor M. Alvarez d72b85f09f Bump version number to 4.5.7. 2026-06-01 12:47:25 +02:00
Victor M. Alvarez 9d093690fc Abort the collection of resources when the MAX_RESOURCES is reached. 2026-06-01 12:45:35 +02:00
Victor M. Alvarez 7488ec7b42 Bump version number to 4.5.6. 2026-05-07 16:47:44 +02:00
Victor M. Alvarez db49ed032e Add repository field to appveyor.yml. 2026-05-05 12:12:48 +02:00
Victor M. Alvarez 1b9f5660a5 Implement yr_popcount64 as __builtin_popcountll is not implemented by MSVC. 2026-05-05 11:04:14 +02:00
Victor M. Alvarez 1e05b0be35 Fix out of bounds read while parsing .NET files.
Closes #2196
2026-05-05 09:53:47 +02:00
Victor M. Alvarez f44a8958e8 Bump version number to 4.5.5. 2025-10-30 10:58:07 +01:00
Victor M. Alvarez 7cfca3fed1 Fix heap overflow. (#2178)
A heap overflow could occur when loading a hand-crafted compiled rules file. If the used field is less than sizeof(void) an integer overflow occurs that bypasses the file validation and causes heap overflow later on.
2025-10-30 10:53:43 +01:00
Victor M. Alvarez 2668c524a4 Terminate wide strings with null char in ss_convert_to_wide
Closes #2175.
2025-10-20 09:39:54 +02:00
Victor M. Alvarez 5cbc7407bd Revert YR_RE_SCAN_LIMIT back to 4096.
The previous change was unintentional.

Closes #2177
2025-10-20 09:31:41 +02:00
Victor M. Alvarez 0f0c667c05 Fix typo 2025-09-05 09:46:39 +02:00
Victor M. Alvarez 1fb9cfdee5 Fix compilation issue due to wrong operator. 2025-09-05 09:24:23 +02:00
Victor M. Alvarez 6e11b5ae1f fix: implement the --no-follow-symlinks option in Windows.
Until now this option was working only on POSIX systems.
2025-09-03 16:47:17 +02:00
Victor M. Alvarez 092187edc9 Adds maintenance mode warning
Adds a warning banner to the README indicating that the project is in maintenance mode, directing users to the YARA-X project for further information.
2025-06-04 13:52:28 +02:00
Victor M. Alvarez 7ff39042be bump version number to 4.5.4. 2025-05-26 18:06:13 +02:00
Victor M. Alvarez 6c8accd96a bump version number to 4.5.3. 2025-05-26 18:02:53 +02:00
Victor M. Alvarez 2e64b4c12d fix: escape new line and carriage returns characters when printing file names.
Matches on files whose name contains such characters are not properly printed.
2025-05-22 18:51:07 +02:00
Victor M. Alvarez bae530c7f0 Remove Bazel as a build system. (#2144)
Bazel was the build system used by VirusTotal. Now that VirusTotal has moved to YARA-X, maintaining the Bazel infrastructure working is painful, specially with the backward incompatible changes introduced in recent versions of Bazel.
2025-04-09 20:44:51 +02:00
Victor M. Alvarez 93d1de6db6 Add check for null pointers in yr_lex_parse_rules_bytes and yr_lex_parse_rules_string
Closes #2139
2025-02-27 11:43:44 +01:00
Victor M. Alvarez 42297f8595 Disable cache in Bazel build workflow 2024-12-11 11:22:07 +01:00
Victor M. Alvarez f1ca8b754a Rename cache trying to solve issue with Bazel build 2024-12-11 11:19:42 +01:00
Victor M. Alvarez 610e88fb75 Fix typo in documentation. 2024-12-11 11:10:46 +01:00
Victor M. Alvarez 1fb43ebff2 Upgrade to actions/cache@v4.
GitHub is deprecating versions 2 and 3.
2024-12-11 10:26:05 +01:00
Victor M. Alvarez 2ff13ab999 fix: large memory consumption while parsing corrupted PE. (#2120)
After #2119 `yara` is consuming a large amount of memory while parsing 9bddb45c44d9c25a4f97ef800cb110de5e6a15349bac05d389c8bda37902f25a. That's because after the change it doesn't limit the total number of imported functions, only the total number of parsing attempts, but the count is reset with each import entry. This file has a large number of entries and a large number of functions per entry, the total number of functions is very high.

It turns out that we must limit both the total number of correctly parsed functions (for cases like this one), and the total number of parsing attempts (for cases like the one #2119 was aiming to solve).
2024-11-28 13:31:32 +01:00
Victor M. Alvarez b61ce3c4a3 Upgrade upload-artifact action to v4 2024-11-26 16:25:46 +01:00
Victor M. Alvarez 688268d839 Update AppVeyor token. 2024-09-10 10:52:59 +02:00
Victor M. Alvarez 1628e61f8e Bump version to 4.5.2 2024-09-10 10:44:46 +02:00
Victor M. Alvarez 44fd094544 Fix regression introduced in 6209630
One section entry was being ignored while parsing file b200f89fe313b6311e444e37725cae95127797ddb430e711c788c264acf92eb0 because we were forcing every resource entry to be shorter than the PE itself.

Although this sanity check makes sense, with truncated files this can lead to resource entries that are ignored. Here we make the sanity check more permissive, allowing entries that are larger than the PE  file, but rejecting entries with ridiculously large sizes.
2024-09-10 09:35:08 +02:00
Victor M. Alvarez a8d59da636 Use MacOS 13 in build workflow.
For some reason in MacOS 14 the build fails because the `configure` script is unable to find the Jansson library, even thought it is correctly installed by `brew`.
2024-08-02 10:35:51 +02:00
Victor M. Alvarez 9f3da0911f Use latest MacOS in build workflow. 2024-08-02 10:24:56 +02:00
Victor M. Alvarez 17fc88ef48 Remove all references to ERROR_TOO_MANY_SCAN_THREADS
This error code is not used anymore. Closes #2068.
2024-08-02 10:01:16 +02:00
Victor M. Alvarez 2a9f61d484 Mitigate stack overflow when scanning very deep directory trees.
Closes #2088.
2024-08-01 11:42:01 +02:00
Victor M. Alvarez b68de47e82 Use YR_MAX_PATH instead of MAX_PATH (#2090)
Replace all instances of `MAX_PATH` with `YR_MAX_PATH`.
2024-08-01 11:29:48 +02:00
Victor M. Alvarez c70d927719 Fix warning
`_rich_version` in PE module should return an `int64_t` instead of `uint64_t`.
2024-07-26 11:14:18 +02:00
Victor M. Alvarez cbc982d754 Fix crash while parsing PE Rich header
File e77b007c9a964411c5e33afeec18be32c86963b78f3c3e906b28fcf1382f46c3 has a Rich header of only 8 bytes, which is smaller than the RICH_SIGNATURE structure. This was causing a crash when some of the `rich_xxx` functions were used with this file.
2024-07-24 14:31:30 +02:00
Victor M. Alvarez 6fe197e1bc Fix null pointer dereference introduced in 8616165.
See: https://oss-fuzz.com/testcase?key=5726747190951936
2024-06-21 16:25:46 +02:00
Victor M. Alvarez 8616165472 Fix segfault with regular expressions that matched the zero-length string.
In regular expressions, repetition operators`{0,0}` and `{,0}` are valid, but they always match the zero-length string. For instance, `a{0,0}` and `[a-z]{0,0}` both match the zero-length string.

When the whole regular expression consists in one of these repetitions it caused a segfault during the evaluation of the regular expression because the `forward_code_ref` field for the root atom in the atom's tree was null.

Closes #2084.
2024-06-19 13:47:58 +02:00
Victor M. Alvarez 608fb3da46 Increase the limit for the maximum number of rows in dotnet module.
See:
https://github.com/VirusTotal/yara-x/issues/138
https://github.com/VirusTotal/yara-x/commit/2f410f7dc26f9ff8fcf3847dc143e07126b90a87
2024-06-19 11:47:47 +02:00
Victor M. Alvarez 4fc1ff822c Recover from syntax error at the end of an included file
When an included file contains an error that makes the parsing fail, the compiler must pop the file name from the stack before continuing parsing the original file, otherwise it will cause the confusing errors described in https://github.com/VirusTotal/yara-python/issues/260
2024-05-31 16:30:11 +02:00
Victor M. Alvarez 3f5b4c73d9 Limit resource names to 1000 character at most.
Fixes high memory usage with corrupt files like bd15a7227770d89546e0a16e4c8da45937d970baa810827a7ceb17abd3138fec.
2024-05-29 12:15:44 +02:00
Victor M. Alvarez 0e5b6bb966 Bump version to 4.5.1 2024-05-25 12:23:51 +02:00
Victor M. Alvarez e453eb1314 Fix infinite loop with certain corrupt files. 2024-05-24 14:03:42 +02:00
Victor M. Alvarez 8a0c19d6f5 Remove printf 2024-05-23 13:44:29 +02:00
Victor M. Alvarez 46ae348687 Remove printf. 2024-05-23 13:43:52 +02:00
Victor M. Alvarez f1640e24ec Allow spaces in regexp repetition operators.
For instance, `x{n, m}`, `x{n ,m}` and `x{n  ,  m}` are all equivalent to `x{n,m}`. This is done for compatibility with YARA-X, but I've seen real-life regular expressions in that contain such spaces, for example:

```
/C:\\Users\\qqq\\.{30, 50}\.pdb/
```
2024-05-22 15:51:43 +02:00
Victor M. Alvarez f0cf225538 Fix issue introduced in 8501962.
`authenticode->verify_flags` are not really bit flags, they are more like error codes.
2024-05-07 13:06:10 +02:00
Victor M. Alvarez 8501962919 Ignore Authenticode signatures that are somehow corrupt. 2024-05-06 10:46:46 +02:00
Victor M. Alvarez 3c93989a5d Try using a specific MacOS version for fixing issue in CI (#2073)
For some reason the jansson library is not being found in the latest MacOS version, even though brew seems to be installing it.
2024-04-30 19:16:22 +02:00
Victor M. Alvarez 4b9b4c0bdb Add sanity check that prevents OOM errors.
The `pe_parse_delayed_imports` function didn't take into account that `pe_rva_to_offset` could return -1 when the RVA can't be translated into a file offset.
2024-04-30 11:41:56 +02:00
Victor M. Alvarez 1be9811ad9 Add sanity check that prevents to much memory consumption with corrupted files
With this change ordinal numbers in imports are limited to 65535, larger ordinal numbers are ignored because they are sign of file corruption.
2024-04-23 09:19:54 +02:00
Victor M. Alvarez 1242223b04 Ignore resource directory entries that with offset == 0. 2024-04-19 17:21:44 +02:00
Victor M. Alvarez b68003853c Restrict DLL names to the printable ASCII range. 2024-04-19 17:20:35 +02:00
Victor M. Alvarez 5317a2b349 Fix endianness issue. 2024-04-08 15:49:07 +02:00
Victor M. Alvarez 620963092c Better sanitation while parsing corrupted resources. 2024-04-08 15:33:35 +02:00
Victor M. Alvarez 80972f0b4c Populate dotnet.resources[x].offset and dotnet.resources[x].length even if falling outside of the file
Until now, these two fields were populated only when the offset and offset + length were within the file boundaries. This meant that the fields were undefined for some files that were truncated. For instance, 3323480fc4e35f73a8e93c4a0658c818d7e517df7ba15ba4cbb5cd2b6058cb0f.
2024-04-08 12:04:17 +02:00
Victor M. Alvarez 9c26038171 Fix alignment check in 32-bits. 2024-04-08 11:57:00 +02:00
Victor M. Alvarez 3395fee53c Remove assertion from test-aligment.c
`off_t` is not 64 bits in all platforms (like Win32)
2024-04-08 10:53:32 +02:00
Victor M. Alvarez 924fa58ce9 Fix issue #2065
The issue was causing false negative with certain patterns.
2024-04-08 10:28:31 +02:00
Victor M. Alvarez 833a580430 Fix issue #2050.
See also PR #2048.
2024-04-07 17:56:43 +02:00
Victor M. Alvarez 7b4dcd8cce Fix alignment tests.
They were returning OK in all cases, it was broken in cba6932759.
2024-04-07 17:56:36 +02:00
Victor M. Alvarez fedee98f9d Fix syntax error in .readthedocs.yaml 2024-03-26 19:21:08 +01:00
Victor M. Alvarez 7fa7465675 Add requirements.txt for documentation. 2024-03-26 19:19:47 +01:00
Victor M. Alvarez 2570c1f931 Create .readthedocs.yaml
This file allows ReadTheDocs to build the documentation, generating the HTML for it.
2024-03-26 19:07:48 +01:00
Victor M. Alvarez 94b7da931c Add test case for math.entropy where input is an empty string. 2024-03-25 10:49:06 +01:00
Victor M. Alvarez ff959e562a Add more test cases. 2024-03-20 15:49:14 +01:00
Victor M. Alvarez c80cd9debf Fix issue with matches operator not matching empty strings
The `matches` operator was returning false if the left operand was an empty strings. So, `"" matches <some regexp>` was returning false regardless of the regexp used. However, some regexp *do* match the empty strings, like for example `/foo|/`.
2024-03-20 15:47:37 +01:00
Victor M. Alvarez 87485021cf Fix integer overflow causing issue when parsing directory table
File e64e806c6df76f245c9b1288f59198bc9478329cfdd2d7ddcb9490a57d0b3cf4 was not properly parsed because `NumberOfRvaAndSizes` overflowed and became negative.
2024-03-20 09:22:53 +01:00
Victor M. Alvarez 74c1a0c8a6 Relax check in pe_get_directory_entry.
Some PE files have a NumberOfRvaAndSizes equal to zero. Even if these files are not accepted by the Windows loader, they can be parsed, and useful information can be extracted from them. By relaxing the sanity check in pe_get_directory_entry we are no able to parse such files (like 0aa527fd26c8e7fa7f3476b6d7eb8f22c071ff4c0fd3ed3797fa90ceb80f24ce).
2024-03-19 15:45:04 +01:00
Victor M. Alvarez 5bf72f2fb0 Fix issue while parsing .NET resources
.NET resources can be found outside the current file. Before this change those resources were being ignored, but now they are included in the `resources` array. The `name` and `length` fields are kept undefined though. So, external resources have only the `name` field set.
2024-03-18 20:21:12 +01:00
Victor M. Alvarez c009195c1e Apply stricter sanity checks while parsing PE resources.
Corrupted file `c10a733e4899dbd03d537d7832efa71016f618e9fd1bffa35b8265df359a91f8` was producing tons of invalid resource entries.
2024-03-08 12:28:57 +01:00
Victor M. Alvarez a0241546df Remove check in dotnet_is_dotnet that doesn't seem necessary.
This function was checking the first two bytes at the entrypoint of .NET files, if the bytes were not `FF 25` the file was not considered a .NET file. This check was overly restrictive, as some files like `8fa7fe73a65296e9ca8301734a0deaa298cda0b7a65f6b7d2ef6d1c8bbb8cd7a` don't have such files at the entrypoint.
2024-03-07 10:39:43 +01:00
Victor M. Alvarez 8242721801 Fix issue in pe_rva_to_offset for some files.
This function was returning a wrong RVA for files like `67508ec9cbd9f82c6aea8a93ca27fd3684d368664470397755f8d70934d481fb`, when a section's virtual size is smaller than its physical size.
2024-03-07 10:33:33 +01:00
Victor M. Alvarez 9490a0c00c Do not abort resource iteration too early when some entry is truncated.
Failing to parse some resource directory does not mean that we can't keep parsing other directories. For instance, with file `0a65e22cdff348be11739122906355af728f6247fb849f98d69a6f6d51103071` YARA was aborting the parsing too early and extracted a single resource, while the file has more resources that could be parsed correctly.
2024-03-06 12:00:27 +01:00
Victor M. Alvarez 4793b49dd7 Fix issue while parsing PE rich header.
YARA was making the assumption that the 12 bytes following the `DanS` header contained 3 copies of the 32-bits XOR key, but these bytes are actually padding. As these bytes were usually filled with zeroes before applying the XOR key, they appear to contain the key itself after the XOR operation. However, files like `043066108b68b30fc2c475eae8edfafc080be7d451600eaa283d2c750bddbceb` don't contain zeroes in those bytes, and therefore were not satisfying YARA's assumption.

YARA-X was right: https://github.com/VirusTotal/yara-x/blob/6ada059b9e4b328e2341b42304765c5614fc89af/lib/src/modules/pe/parser.rs#L687-L693
2024-03-04 18:26:19 +01:00
Victor M. Alvarez a1883addcb Update example in yara-python's documentation.
As discussed in https://github.com/VirusTotal/yara-python/issues/247, the example using `StringIO` worked fine in Python 2, but ti doesn't work in Python 3. Now that Python 2 is mostly dead, update the example.
2024-02-29 13:08:03 +01:00
Victor M. Alvarez 8fa55cde4c Bump version number to 4.5.0 2024-02-13 12:33:22 +01:00
Victor M. Alvarez 4369ca6a1b Fix endianness issues in macho module (#2041)
This is backward compatible change that affects the `magic` field. After this change the value in the `magic` field looks exactly as it looks in the file regardless of the endianness of the current platform, if the file starts with `CA FE BA BE` the value in magic is `0xCAFEBABE`, not `0xBEBAFECA` as it used to be in little-endian architectures.
2024-02-12 15:23:09 +01:00
Victor M. Alvarez f3b3027154 Allow quantifiers {0} and {0,0}.
Regexps with quantifiers `{0}` and `{0,0}` were considered syntactically invalid. These quantifiers are not  actually useful, but they are now allowed for compatibility with other regexp engines.

Closes #2037.
2024-02-12 11:47:17 +01:00
Victor M. Alvarez c1c5d89052 pe.is_signed is now defined for all PE files.
Until now, `pe.is_signed` was undefined for every PE file that was not signed, making impossible to use it in negated conditions, like `pe.is_pe and not pe.is_signed`. With this change, `pe.is_signed` is false for every PE file that is not signed.

Closes #2040
2024-02-12 11:10:49 +01:00
Victor M. Alvarez 9ff9c4c6ca Temporary fix for SIGSEGV caused by authenticode parser.
See: https://github.com/avast/authenticode-parser/issues/19 for details.
2024-02-09 10:47:12 +01:00
Victor M. Alvarez 3342aa06f6 Fix bug in magic module when libmagic returns null pointer.
The pointer returned from `libmagic` was passed directly to `yr_strdup` (a wrapper of `strdup`), but this function has undefined behavior when the argument is null.
2024-02-08 11:28:17 +01:00
Victor M. Alvarez 3a2b4d16c5 Upgrade magic library to version 5.45. 2024-02-06 13:53:11 +01:00
Victor M. Alvarez e065be6716 Add test case for magic field in macho module.
This should confirm an issue with the endianness of `magic` field in big-endian platforms.
2024-01-30 21:32:02 +01:00
Victor M. Alvarez f5edf4e5f5 Run the bigendian GitHub workflow with the code from the current commit (#2036)
Instead of downloading the latest master branch, use the code in the current branch. Until know, this workflow was always operating wit the latest commit in the master branch.
2024-01-30 21:29:10 +01:00
Victor M. Alvarez ff4a923fac Enable macho module when running tests 2024-01-30 17:12:43 +01:00
Victor M. Alvarez 4d696a91b1 Fix test cases 2024-01-15 22:31:18 +01:00
Victor M. Alvarez 79794c4053 Fix issue with regexps not matching empty strings.
Some regexps like `/(abc|)/` where not matching the empty string even if they should. Matching an empty string is not very useful, as such regexp will match on every offset of every file, but this is fixed for correctness.

Also fixes another issue with the `\b` metacharacter in regexps, which was exposed after fixing the main issue.
2024-01-15 16:51:11 +01:00
Victor M. Alvarez bb28999b33 Autoformat test/util.h 2024-01-15 16:34:12 +01:00
Victor M. Alvarez a3d938b429 Minor style fixes. 2024-01-15 13:07:34 +01:00
Victor M. Alvarez 821c979416 Fix issue in read_blob_signed function in dotnet module.
While porting the `dotnet` module to YARA-X I discovered the the implementation of `read_blob_signed` had a subtle bug. As `first_byte` was declared as `uint8_t` instead of `int8_t`, sign extension when casting the value to a `int32_t` was not done, leading to incorrect values.
2023-12-29 15:50:51 +01:00