Skip to content

libclamav: Fix crash on some platforms with optimization enabled. - #1572

Merged
val-ms merged 2 commits into
Cisco-Talos:mainfrom
jhumlick:CLAM-2859-github-reported-segfault
Sep 26, 2025
Merged

val-ms merged 2 commits into
Cisco-Talos:mainfrom
jhumlick:CLAM-2859-github-reported-segfault

Conversation

@jhumlick

@jhumlick jhumlick commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor

Some compilers were packing the pdfname_action structure with difference sizes in memory with optimization enabled while assigning a pointer to a member of an array of these structures, resulting in the line calling the callback from said structure accessing invalid memory. This fix changes the logic so that rather than assign the pointer to the struct containing the callback, the string that would result in the pointer assignment later on is changed to result in the same assignment. This fixes the issue on all tested platforms.

#1566
CLAM-2859

@jhumlick
jhumlick requested a review from val-ms September 17, 2025 16:31
@jhumlick jhumlick self-assigned this Sep 17, 2025

@val-ms val-ms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think the issue is from optimizing out pointer assignment.
I think the issue is that optimization resulted in different size in memory when packing this struct:

&(struct pdfname_action){"URI", OBJ_DICT, STATE_ANY, STATE_URI, NAMEFLAG_NONE, URI_cb};

versus when packing the larger array of similar structs.
Regardless, I believe this fix is correct to resolve the crash.

Comment thread libclamav/pdf.c Resolved
Some compilers were optimizing out pointer assignment to a structure
containing the address of the callback to be called. This resulted in
the line calling the callback accessing invalid memory. This fix changes
the logic so that rather than assign the pointer to the struct
containing the callback, the string that would result in the pointer
assignment later on is changed to result in the same assignment. This
fixes the issue on all tested platforms.

Cisco-Talos#1566
CLAM-2859
@val-ms
val-ms force-pushed the CLAM-2859-github-reported-segfault branch from a41300e to 636224b Compare September 25, 2025 17:22
@val-ms
val-ms merged commit a5cdc7f into Cisco-Talos:main Sep 26, 2025
jhumlick added a commit to jhumlick/clamav that referenced this pull request Nov 4, 2025
…bled (Cisco-Talos#1572)

Compiler optimization results in invalid memory access on some 
systems with the PDF `pdfname_action` pointer dereference. 

This fix changes the logic so that rather than assign the pointer to
the struct containing the callback, the string that would result in
the pointer assignment later on is changed to result in the same
assignment. This fixes the issue on all tested platforms.

Resolves: Cisco-Talos#1566

CLAM-2859
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.

2 participants