Skip to content

libclamav: recover HWP3 attachments after paragraph errors - #1796

Open
jhumlick wants to merge 1 commit into
Cisco-Talos:mainfrom
jhumlick:CLAM-2953-HWP3-parser-reachability
Open

libclamav: recover HWP3 attachments after paragraph errors#1796
jhumlick wants to merge 1 commit into
Cisco-Talos:mainfrom
jhumlick:CLAM-2953-HWP3-parser-reachability

Conversation

@jhumlick

Copy link
Copy Markdown
Contributor

Resynchronize with additional information blocks when malformed paragraph
metadata interrupts HWP3 parsing. Fall back to scanning the complete content
stream and validate fixed image metadata lengths to avoid underflow.

Add a regression test confirming later embedded content remains detectable.

CLAM-2953

@jhumlick
jhumlick requested a review from val-ms August 12, 2026 23:05
@jhumlick jhumlick self-assigned this Aug 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 082d426cc0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread libclamav/hwp.c
Comment on lines +1614 to +1616
if (infolen < HWP3_IMAGE_INFO_SIZE) {
cli_errmsg("HWP3.x: Information Block[%llu]: Image Data block is too short: %u\n", infoloc, infolen);
return CL_EFORMAT;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Continue scanning after rejecting a short image block

When a document has a valid paragraph section but an undersized image block before a later attachment, returning CL_EFORMAT here immediately stops the information-block loop. Because paragraph_parse_failed remains false, the fallback at the end of hwp3_cb is also skipped, so the later attachment is never scanned as a nested file and attachment-level signatures can be bypassed. The equivalent background-image check has the same problem; these malformed blocks should be skipped safely or trigger the full recovery path rather than aborting attachment scanning.

Useful? React with 👍 / 👎.

Comment thread libclamav/hwp.c
Comment on lines +1820 to +1823
next = payload + infolen;
/* Requiring a valid following header further avoids treating paragraph data as a block. */
if (!hwp3_infoblk_1_header_is_plausible(map, next))
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Accept a recovered attachment that ends at EOF

If a malformed HWP3 paragraph is followed by a complete attachment whose payload reaches EOF, next == map->len and this mandatory following-header check rejects it. This is readily produced by omitting the information-block terminator from an already malformed document; the fallback then scans only the complete HWP stream, so exact-hash and format-aware signatures for the embedded attachment do not run against the attachment layer. Treating exact EOF as a plausible end would preserve recovery for this case.

Useful? React with 👍 / 👎.

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.

1 participant