[pdf] Hostile corpus: six pinned pdf.js fuzz files; damaged page trees say so
This commit is contained in:
@@ -158,6 +158,9 @@ pub fn apply(engine: &Engine, bytes: &[u8], password: Option<&str>, edits: &Edit
|
||||
if !edits.annotations.is_empty() || !edits.stamps.is_empty() {
|
||||
let mut doc = lopdf_load(&cur, None)?;
|
||||
let pages: Vec<ObjectId> = doc.get_pages().values().copied().collect();
|
||||
if pages.is_empty() {
|
||||
return Err(PdfError::Damaged("its page tree is damaged, so Pictor cannot add to its pages safely".into()));
|
||||
}
|
||||
for a in &edits.annotations {
|
||||
let &page = pages.get(a.page).ok_or(PdfError::NoSuchPage(a.page + 1))?;
|
||||
add_annotation(&mut doc, page, a)?;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# Fetches real-world hostile PDFs for the worker's hostile test (crates/worker/tests/hostile_pdf.rs) into
|
||||
# fixtures/fetched/. Never in git. Every file is pinned by sha256 and by the source commit; a mismatch is deleted
|
||||
# and the script fails. The generated fixtures in the test need nothing; these add files other tools broke on.
|
||||
# Source: the pdf.js test corpus (mozilla/pdf.js, test/pdfs), commit bb1539a2c9b5b76d070284cca9091717133d8bf1.
|
||||
# Usage: powershell -File fixtures-fetch/fetch.ps1
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$Commit = 'bb1539a2c9b5b76d070284cca9091717133d8bf1'
|
||||
$Base = "https://raw.githubusercontent.com/mozilla/pdf.js/$Commit/test/pdfs"
|
||||
$Files = [ordered]@{
|
||||
'GHOSTSCRIPT-698804-1-fuzzed.pdf' = '62e518ca7894e8b8b8ed9927da3007cdc5e9ccc5b111bbb22d6101d4a8d7490e'
|
||||
'PDFBOX-3148-2-fuzzed.pdf' = '1c780335b494ac52eae9fa4d05f1bba88c18ca6b24e6e302b9f271de05e256aa'
|
||||
'bad-PageLabels.pdf' = 'eff0ee7d1cf2e1a7ccfb25a8fc4c2bbea0ec23c838b61a199a57dbb732ddeaad'
|
||||
'boundingBox_invalid.pdf' = 'f85be7aaf217f8f1864b910501d4aeea53f3d7a503df5b81dd6aaa267e5968ad'
|
||||
'checkbox-bad-appearance.pdf' = '0cd13bf7375a2b6b9b01bb694aefcfe9dac225105cb9ad7e03798783b3318ad9'
|
||||
'helloworld-bad.pdf' = 'c3e22ea5d7e6f5b7218d76abce4284728889df516a93c1b74a82c4fd69aa1639'
|
||||
}
|
||||
$Dest = Join-Path $PSScriptRoot '..\fixtures\fetched'
|
||||
New-Item -ItemType Directory -Force $Dest | Out-Null
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
foreach ($name in $Files.Keys) {
|
||||
$path = Join-Path $Dest $name
|
||||
if ((Test-Path $path) -and ((Get-FileHash -Algorithm SHA256 $path).Hash.ToLowerInvariant() -eq $Files[$name])) { continue }
|
||||
Invoke-WebRequest -UseBasicParsing -Uri "$Base/$name" -OutFile $path
|
||||
$got = (Get-FileHash -Algorithm SHA256 $path).Hash.ToLowerInvariant()
|
||||
if ($got -ne $Files[$name]) { Remove-Item $path; throw "$name sha256 mismatch: expected $($Files[$name]), got $got" }
|
||||
Write-Host "fetched $name"
|
||||
}
|
||||
Write-Host "$($Files.Count) hostile PDFs in $Dest"
|
||||
Reference in New Issue
Block a user