Files
capa/capa
Devyansh Somvanshi 8c138e3d22 loader: handle struct.error from dnfile and raise CorruptFile with a clear message (#2872)
* loader: handle struct.error from dnfile and show clear CorruptFile message

When .NET metadata is truncated or invalid, dnfile can raise struct.error.
Catch it in DnfileFeatureExtractor and DotnetFileFeatureExtractor and
re-raise as CorruptFile with a user-friendly message.

Fixes #2442

* dnfile: centralize dnPE() loading in load_dotnet_image helper

Add load_dotnet_image() to dnfile/helpers.py that calls dnfile.dnPE()
and catches struct.error, raising CorruptFile with the original error
message included (f"Invalid or truncated .NET metadata: {e}").

Both DnfileFeatureExtractor and DotnetFileFeatureExtractor now call the
helper instead of duplicating the try/except block, and their direct
import of struct is removed.

Addresses review feedback on #2872.

* style: reformat dnfile files with black --line-length=120

Fixes CI code_style failure by applying the project's configured
line length (120) instead of black's default (88).

---------

Co-authored-by: Moritz <mr-tz@users.noreply.github.com>
Co-authored-by: Mike Hunhoff <mike.hunhoff@gmail.com>
2026-03-10 14:20:48 -06:00
..
2025-12-18 17:55:49 -07:00
2025-11-20 08:37:49 -07:00
2025-01-15 08:52:42 -07:00
2025-01-15 08:52:42 -07:00
2025-01-15 08:52:42 -07:00
2025-11-20 08:37:49 -07:00