Files
Pictor-public/fixtures-fetch/fetch.ps1
T

29 lines
2.0 KiB
PowerShell

# 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"