## TL;DR
A parser expecting clean PDF structure chokes on samples that blend formats: a PDF carrying an embedded HTML payload, malformed objects, or a file that is HTML wearing a PDF extension. Make the parser defensive: identify the real file type by content, route HTML to the HTML analyser, wrap parsing in a sandbox with strict limits, and treat a parser crash itself as a suspicious signal worth flagging, since malformed files are an attacker technique, not an accident.

```text
the agent's pdf parser broke on a smuggled-html attachment mid-analysis
```

## Use this when
- The agent PDF step throws or hangs on a specific campaign attachment.
- File inspection shows the attachment is not a well-formed PDF.

## Not for this skill when
- The PDF is a legitimate complex document the parser version mishandles. A parser upgrade may be the whole fix.
- The attachment is a pure HTML file with no PDF involvement. Use the HTML smuggling handling.

## Steps
1. Identify the sample true type from its first bytes and structure, ignoring the extension. Verify: the real format is established.
2. Reproduce the parser failure in isolation with logging, capturing where it throws or loops. Verify: the failing construct in the file is located.
3. Route by true type: real PDFs to the PDF parser, HTML content to the HTML analyser, and hybrids to both with results merged. Verify: routing uses content, not the file name.
4. Run all parsing in a sandboxed worker with time, memory and recursion limits, so a hostile file can only kill its own worker. Verify: a crash in testing leaves the agent alive and the item flagged.
5. Re-run the campaign attachment set. Verify: every item yields an analysis or an explicit hostile-format flag, with no agent crashes.

## Variant phrasings
### pdf parser crashes malformed smuggled html attachment
The parser crash variant.
### agent file type detection content not extension parsing
The true type variant.

Compatibility: Common PDF parsing libraries and HTML analysis in agent pipelines, sandboxed worker execution.

## Why it happens
Parsers assume documents follow the format. Attackers author documents that follow it just loosely enough for a victim reader to open while a stricter automated parser dies, so the analysis gap is engineered, not accidental.

## Edge cases / pitfalls
- Keep parser libraries patched; malformed-file crashes are a steady source of parser vulnerabilities.
- A file whose extension and content disagree should raise its risk score automatically.
- Log parser failures as security events, not just errors, so patterns across campaigns are visible.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_E46D8JgrtRFk54xwrDxMbA
