From 9b4d73c94bfc27076ab6d09a36f4fb3ac91f0269 Mon Sep 17 00:00:00 2001 From: grabowski Date: Mon, 23 Nov 2026 10:01:02 +0700 Subject: [PATCH] Nightly fuzzing on cnx01: text, uploads, the signed copy .gitea/workflows/fuzz.yml runs cargo-fuzz (libFuzzer, nightly Rust) at 03:00 Chiang Mai time on runner02 on cnx01 (runs-on: cnx01; the label comes with cnx-network-clan PR #170), 10 minutes a target, under nice -n 19 (.gitea/scripts/fuzz.sh). Targets, bodies in src/fuzzing.rs: - text: passport zones and OCR output (whatever from_ocr returns must parse), positions, names, dates, Thai numbers, agreement texts and the contract diff. - upload: a file as files::sniff types it, through the pack's image and PDF code to a finished A4 page (pack::pdf::sides), EXIF orientation. - signed_copy: the drawn signature's PNG, or any text as the agreement, in the signed copy's PDF. fuzz/seeds/ holds small real files to start from (JPEG with JFIF and EXIF, PNG with pHYs, palette PNG, WebP lossy and lossless, A4 and landscape PDF, a drawn signature, zone, OCR, map links, Thai names). The grown corpus stays in the runner's cache; a crash fails the job and leaves its input as the artifact fuzz-findings, which goes into tests/fuzz_cases// with the fix. tests/fuzz_cases.rs replays those and the seeds on every push, on stable. No sanitizer (safe Rust, about three times the inputs), debug assertions on, 10 s and 2 GB per input count as findings. DRAWING_LIMIT moved to agreements so the target uses the client page's limit. A local run of 60 s each in a Linux container: 635,522 / 9,763 / 4,089 inputs, peak 62 MB, nothing found. --- .gitea/scripts/fuzz.sh | 49 ++++++++++++ .gitea/workflows/ci.yml | 7 +- .gitea/workflows/fuzz.yml | 63 +++++++++++++++ AGENTS.md | 7 ++ docs/PLAN.md | 25 +++--- fuzz/.gitignore | 6 ++ fuzz/Cargo.toml | 41 ++++++++++ fuzz/fuzz_targets/signed_copy.rs | 3 + fuzz/fuzz_targets/text.rs | 3 + fuzz/fuzz_targets/upload.rs | 3 + fuzz/seeds/signed_copy/agreement.txt | 8 ++ fuzz/seeds/signed_copy/drawn.png | Bin 0 -> 798 bytes fuzz/seeds/text/date.txt | 1 + fuzz/seeds/text/dms.txt | 1 + fuzz/seeds/text/maps.txt | 1 + fuzz/seeds/text/names.txt | Bin 0 -> 109 bytes fuzz/seeds/text/ocr.txt | 3 + fuzz/seeds/text/osm.txt | 1 + fuzz/seeds/text/thai-id.txt | 1 + fuzz/seeds/text/versions.txt | Bin 0 -> 90 bytes fuzz/seeds/text/zone.txt | 2 + fuzz/seeds/upload/a4.pdf | Bin 0 -> 997 bytes fuzz/seeds/upload/landscape.pdf | Bin 0 -> 995 bytes fuzz/seeds/upload/lossless.webp | Bin 0 -> 164 bytes fuzz/seeds/upload/palette.png | Bin 0 -> 2200 bytes fuzz/seeds/upload/phone-photo-turned.jpg | Bin 0 -> 1783 bytes fuzz/seeds/upload/photo.webp | Bin 0 -> 486 bytes fuzz/seeds/upload/plain.jpg | Bin 0 -> 1400 bytes fuzz/seeds/upload/scan-200dpi.png | Bin 0 -> 408 bytes src/agreements/mod.rs | 3 + src/fuzzing.rs | 97 +++++++++++++++++++++++ src/lib.rs | 2 + src/web/client.rs | 5 +- tests/fuzz_cases.rs | 53 +++++++++++++ tests/fuzz_cases/signed_copy/README.md | 2 + tests/fuzz_cases/text/README.md | 2 + tests/fuzz_cases/upload/README.md | 2 + tests/main.rs | 1 + 38 files changed, 376 insertions(+), 16 deletions(-) create mode 100644 .gitea/scripts/fuzz.sh create mode 100644 .gitea/workflows/fuzz.yml create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/signed_copy.rs create mode 100644 fuzz/fuzz_targets/text.rs create mode 100644 fuzz/fuzz_targets/upload.rs create mode 100644 fuzz/seeds/signed_copy/agreement.txt create mode 100644 fuzz/seeds/signed_copy/drawn.png create mode 100644 fuzz/seeds/text/date.txt create mode 100644 fuzz/seeds/text/dms.txt create mode 100644 fuzz/seeds/text/maps.txt create mode 100644 fuzz/seeds/text/names.txt create mode 100644 fuzz/seeds/text/ocr.txt create mode 100644 fuzz/seeds/text/osm.txt create mode 100644 fuzz/seeds/text/thai-id.txt create mode 100644 fuzz/seeds/text/versions.txt create mode 100644 fuzz/seeds/text/zone.txt create mode 100644 fuzz/seeds/upload/a4.pdf create mode 100644 fuzz/seeds/upload/landscape.pdf create mode 100644 fuzz/seeds/upload/lossless.webp create mode 100644 fuzz/seeds/upload/palette.png create mode 100644 fuzz/seeds/upload/phone-photo-turned.jpg create mode 100644 fuzz/seeds/upload/photo.webp create mode 100644 fuzz/seeds/upload/plain.jpg create mode 100644 fuzz/seeds/upload/scan-200dpi.png create mode 100644 src/fuzzing.rs create mode 100644 tests/fuzz_cases.rs create mode 100644 tests/fuzz_cases/signed_copy/README.md create mode 100644 tests/fuzz_cases/text/README.md create mode 100644 tests/fuzz_cases/upload/README.md diff --git a/.gitea/scripts/fuzz.sh b/.gitea/scripts/fuzz.sh new file mode 100644 index 0000000..5e5c63f --- /dev/null +++ b/.gitea/scripts/fuzz.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# The nightly fuzzing (.gitea/workflows/fuzz.yml); also runs on any Linux +# machine with rustup. +# bash .gitea/scripts/fuzz.sh setup nightly Rust and cargo-fuzz +# bash .gitea/scripts/fuzz.sh run each target for FUZZ_SECONDS (600) +# Targets: fuzz/fuzz_targets/, bodies in src/fuzzing.rs. The first corpus +# folder (fuzz/corpus/) takes what the run finds; the seeds and the +# cases that once broke a target are read as well. +set -euo pipefail +cd "$(dirname "$0")/../.." +export PATH="$HOME/.cargo/bin:$PATH" + +case "${1:?setup or run}" in +setup) + bash .gitea/scripts/rust-toolchain.sh stable >/dev/null + rustup toolchain install nightly --profile minimal + # a fixed version, so the cache keeps one build + command -v cargo-fuzz >/dev/null || cargo install cargo-fuzz --version 0.13.1 --locked + cargo +nightly --version + ;; +run) + seconds=${FUZZ_SECONDS:-600} + # the app's own lock file, so the targets build the versions it runs + cp Cargo.lock fuzz/Cargo.lock + # No sanitizer: the code is safe Rust, and without AddressSanitizer each + # target tries about three times as many inputs. Debug assertions stay + # on (overflow checks), as cargo-fuzz builds by default. + nice -n 19 cargo +nightly fuzz build -O -s none + failed=() + for target in $(cargo +nightly fuzz list); do + mkdir -p "fuzz/corpus/$target" "fuzz/artifacts/$target" + echo "== $target, ${seconds} s" + # -timeout: one input taking 10 s is a finding; -rss_limit_mb: so is + # one that needs 2 GB (cnx01 gives the app 1 GB in all) + if ! nice -n 19 cargo +nightly fuzz run -O -s none "$target" \ + "fuzz/corpus/$target" "fuzz/seeds/$target" "tests/fuzz_cases/$target" -- \ + -max_total_time="$seconds" -timeout=10 -rss_limit_mb=2048 -max_len=1048576 \ + -print_final_stats=1; then + failed+=("$target") + fi + done + du -sh fuzz/corpus/* || true + if [ ${#failed[@]} -gt 0 ]; then + echo "found something: ${failed[*]} (artifact fuzz-findings)" + ls -l fuzz/artifacts/*/ || true + exit 1 + fi + ;; +esac diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 242dd4f..8d995df 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -14,8 +14,11 @@ # x86_64 on Ubuntu 22.04 (glibc 2.35; .gitea/scripts/build-release.sh) # and signed with the repository secret RELEASE_SIGNING_KEY # (.gitea/scripts/sign-release.sh). cnx01 installs each release -# with that signature only, within 15 minutes, and restarts the app -# on it (cnx-network-clan modules/visa): a push to main is a deploy. +# with that signature only, seconds after the release webhook tells +# it (every 15 minutes it also looks), and restarts the app on it +# (cnx-network-clan modules/visa): a push to main is a deploy. +# Fuzzing runs every night in fuzz.yml; its findings are replayed here +# by tests/fuzz_cases.rs. # A commit message with [skip ci] skips the whole workflow. name: CI diff --git a/.gitea/workflows/fuzz.yml b/.gitea/workflows/fuzz.yml new file mode 100644 index 0000000..11d9e90 --- /dev/null +++ b/.gitea/workflows/fuzz.yml @@ -0,0 +1,63 @@ +# Nightly fuzzing (cargo-fuzz, libFuzzer) of the code that reads what +# reaches the app from outside: what people paste and type, uploaded +# images and PDFs, the drawn signature (src/fuzzing.rs, fuzz/). Only on +# runner02 on cnx01 (label cnx01, cnx-network-clan docs/src/ci-runner.md), +# at 03:00 in Chiang Mai and at the lowest CPU priority, so the services +# there keep first call. The corpus each run grows is kept in the cache +# for the next. A crash fails the job and leaves its input as the artifact +# fuzz-findings; it goes into tests/fuzz_cases// with the fix, +# which every push then replays. Never releases anything. +name: Fuzz + +on: + schedule: + - cron: "0 20 * * *" + workflow_dispatch: + inputs: + seconds: + description: Seconds per target + default: "600" + +concurrency: + group: fuzz + cancel-in-progress: false + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: "0" + +jobs: + fuzz: + name: fuzz + runs-on: cnx01 + timeout-minutes: 120 + env: + FUZZ_SECONDS: ${{ inputs.seconds || '600' }} + steps: + - uses: actions/checkout@v4 + + - name: Nightly Rust and cargo-fuzz + run: bash .gitea/scripts/fuzz.sh setup + + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/cargo-fuzz + ~/.cargo/registry/index + ~/.cargo/registry/cache + fuzz/target + fuzz/corpus + # a new key each run, so the grown corpus is saved every night + key: fuzz-${{ github.run_id }} + restore-keys: fuzz- + + - name: Fuzz + run: bash .gitea/scripts/fuzz.sh run + + - name: Keep the findings + if: failure() + uses: https://github.com/christopherHX/gitea-upload-artifact@v4 + with: + name: fuzz-findings + path: fuzz/artifacts/ + retention-days: 30 diff --git a/AGENTS.md b/AGENTS.md index e3b87fe..797c122 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -53,6 +53,13 @@ Lanna Desk (lannadesk.com, the app `visa`) holds passport data of real people. R smallest input and lands in `proptest-regressions/`: commit that file with the fix, so every run tries the case first. `PROPTEST_CASES=50000 cargo test --lib props` looks harder than the default 256. +- **Fuzzing** runs every night on cnx01 (`.gitea/workflows/fuzz.yml`, + `fuzz/`, bodies in `src/fuzzing.rs`). A finding arrives as the failed job's + artifact `fuzz-findings`: put the input into `tests/fuzz_cases//`, + named after what it broke, and fix the code until `cargo test` passes. A + new reader of outside input belongs in a target's body. On Linux: + `bash .gitea/scripts/fuzz.sh setup`, then `FUZZ_SECONDS=60 bash + .gitea/scripts/fuzz.sh run`. - **Writing** for people (pages, docs) follows the house style: plain American English in whole sentences, no em dashes, "Nov 17, 2026" in tables. diff --git a/docs/PLAN.md b/docs/PLAN.md index e8c8b4b..d93d621 100644 --- a/docs/PLAN.md +++ b/docs/PLAN.md @@ -736,16 +736,21 @@ cases in the tests. the contract diff, the journal hash, and the PDF's line wrap. Their first run found that the photo reader dropped a one-letter given name (the K of SMITH</` with its fix, which `cargo test` replays on + every push. The multipart reading itself is axum's (multer), so no + target of ours. +- [ ] The nightly job runs on runner02 on cnx01 (Alex, Nov 23, 2026), by + its own label `cnx01` (cnx-network-clan PR), at 03:00 and at the lowest + CPU priority (`nice`), so the app keeps first call on the CPU. ## Open questions diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..577668c --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,6 @@ +/target/ +/corpus/ +/artifacts/ +/coverage/ +# a copy of ../Cargo.lock plus libfuzzer-sys, made before each build +/Cargo.lock diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..a243afe --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,41 @@ +# The fuzz targets (cargo-fuzz, nightly Rust): .gitea/workflows/fuzz.yml +# runs them every night on cnx01. Each one only calls its body in +# src/fuzzing.rs, which tests/fuzz_cases.rs replays on stable. +# Locally (Linux): cp Cargo.lock fuzz/ && cargo +nightly fuzz run text +[package] +name = "visa-fuzz" +version = "0.0.0" +edition = "2024" +publish = false + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" +visa = { path = ".." } + +# its own workspace, so the app's cargo commands leave it alone +[workspace] +members = ["."] + +[[bin]] +name = "text" +path = "fuzz_targets/text.rs" +test = false +doc = false +bench = false + +[[bin]] +name = "upload" +path = "fuzz_targets/upload.rs" +test = false +doc = false +bench = false + +[[bin]] +name = "signed_copy" +path = "fuzz_targets/signed_copy.rs" +test = false +doc = false +bench = false diff --git a/fuzz/fuzz_targets/signed_copy.rs b/fuzz/fuzz_targets/signed_copy.rs new file mode 100644 index 0000000..1ea534e --- /dev/null +++ b/fuzz/fuzz_targets/signed_copy.rs @@ -0,0 +1,3 @@ +#![no_main] + +libfuzzer_sys::fuzz_target!(|data: &[u8]| visa::fuzzing::signed_copy(data)); diff --git a/fuzz/fuzz_targets/text.rs b/fuzz/fuzz_targets/text.rs new file mode 100644 index 0000000..534bd68 --- /dev/null +++ b/fuzz/fuzz_targets/text.rs @@ -0,0 +1,3 @@ +#![no_main] + +libfuzzer_sys::fuzz_target!(|data: &[u8]| visa::fuzzing::text(data)); diff --git a/fuzz/fuzz_targets/upload.rs b/fuzz/fuzz_targets/upload.rs new file mode 100644 index 0000000..8c15b57 --- /dev/null +++ b/fuzz/fuzz_targets/upload.rs @@ -0,0 +1,3 @@ +#![no_main] + +libfuzzer_sys::fuzz_target!(|data: &[u8]| visa::fuzzing::upload(data)); diff --git a/fuzz/seeds/signed_copy/agreement.txt b/fuzz/seeds/signed_copy/agreement.txt new file mode 100644 index 0000000..9d201c1 --- /dev/null +++ b/fuzz/seeds/signed_copy/agreement.txt @@ -0,0 +1,8 @@ +# 1. Purpose +Lanna Desk keeps your data for your stay. + +- name +- passport + +# 2. ข้อมูลส่วนบุคคล +ข้อมูลส่วนบุคคลของท่านจะถูกเก็บรักษาไว้อย่างปลอดภัย diff --git a/fuzz/seeds/signed_copy/drawn.png b/fuzz/seeds/signed_copy/drawn.png new file mode 100644 index 0000000000000000000000000000000000000000..91099b7a55caa4f517ff1422e49620c4f586b81f GIT binary patch literal 798 zcmeAS@N?(olHy`uVBq!ia0y~yVAKJ!qd3@rBvWCwERcNa>EaktaqI0}>oO%n0oH(9 z*$QdCI#;um()caDe*8FpTGaYi_fjT#YD}Hy#oKn76Q~mtG)z1<{q^I&`yHmOjgHt` zzJG6C6hqOT5?<{CEu!Kf%XAD9cQP?Cy}r5OmqgUM?t5Dt5?p=5%pTl7>~+?nvTf`C z&#TrSdiD5!dF-G11*>J5vJZXMTDbMT^_r}9?S<{Hy{~=S{A-^6_4aHfwKWG5Q%_aB zt9pCj!Sc9Uo8`ChonP&fk(|Bzc~!vr{wVfq9Sw%5Z-b*B>MwDVkD2{E)G7P?ty$Yx zuAVTx-!k>UEW@o_y0w>;Hl!^pKYn4B|v))&XS4B?9IFtbX%2KJ5zZn zTi7SftXo1Mr&+?1jF+{BwesfQy2RYh9+o9IS^dx#H`83spD!Cj7f#>|4!e3b_g2vS z%*N24j~VTx6ee6<9FP#Yf8Lr8QM-KQm#w{b@a=5=Cg;_~kAJ20&J%vNY{N|HqhD7X zR}%|iW?p?-&8q5@P}tYkiM{OXVc!MsUf(>!Wl!6L1Fv>;_HpPWUVYqr@>*FyLaF|j zGZ%pB{`*~>#mA#_^xNDQ*N#`Yu}o_^KXX%zXw7LYf3|5GW(h}0?RnNeE8@6keiP6`b?+bQF9_QuF{R CMndiY literal 0 HcmV?d00001 diff --git a/fuzz/seeds/text/ocr.txt b/fuzz/seeds/text/ocr.txt new file mode 100644 index 0000000..d66f413 --- /dev/null +++ b/fuzz/seeds/text/ocr.txt @@ -0,0 +1,3 @@ +REPUBLIC OF UTOPIA +p c)?-jc=*cKbO@--FRxkz|Rg_thUsTBj0Bunk3jhEB literal 0 HcmV?d00001 diff --git a/fuzz/seeds/text/zone.txt b/fuzz/seeds/text/zone.txt new file mode 100644 index 0000000..97bb66d --- /dev/null +++ b/fuzz/seeds/text/zone.txt @@ -0,0 +1,2 @@ +PH5K8C}c?cqql&q7`sY?{}o~eyn^bP~xU!TwC`(sjW);Wf|bS zJof~oU@`I;qX8^W!NCR(LflP^ZVdnoB^Z{+Kst?vrY=%sd(5kcHRO6V8biXPdDIt- zggov>VYN}AQD+k2NH2eY22}w9M1B%&4F%a@BVZ7t0lylT6ahJ$sFDBFIAOpz(I~A? zKvm>z0T-3c;AoImea{LfOA?Q&rV0&(45NI=JVv2}@-z+`QH8f6X!5+Rh;l8z`?5J5 zx8jl}Vo(>~q%t8PNhsu@LZi&Ypv1H=vb>nCxleP=l=&48<$_9B^@AEJ`avd${S7K0|{V8--ZXkmJ`GjgV94(zBFJcaU%awBU0B-r_4&f_7v%@)=)*k=>4Ue#F4svnwkig*Rj#7`U+vvb zT`NR(B^l=>f?Y{b+|K^bua}4`xo_ojtx>V{3s~8{?b_2_?f)R0jOYlEpaG=K2Q^id zRX74SeF|Tqcre)XVZyJV*{A=VM=-yJraYPOtu*-*%uk@nrW91+wkWza~3uCYmHKm2oB8pF)Z*Y4q|j@07wwSaCi*la_H3LIf^Wgd9|>LT(3%FNVvC%dV-OV z``sw4)XOw#Pa+)d<_FNAB0zwMPogzYkQLSg1|`(zSK^W)Acqn;@i_`H} zT+)OO>f%l+6B3eyLLM5Z4>Qpy(Jcv?UQ8S2V_Y+3e%V8Xpd42Gpo#|lARom3+B;FQ z;9CVgPJ=2Ng%VbfT${F5TA&F5~SV0*&kk6p@XSjL)V$%Z4Fa+YKj$0A17BBpN1`7E)!bGj`lnAljhETRJ$(bVBymbWb4}>;A9Y25b!wCbYp&^LZgF{@VgDl94tbg3zkWx z{d>$WYLTUKa-!Gs`~@bnKJ%TOaHHP-HP;KZ){cMv4J!gYl&8;IJw4}u{iV3<&&+eV z3mRwg7O)sOxF29mGdm!7fBw3xY_BrtO)Ry|jLwg7a(Z KCcR0#j0^x`T|EQ< literal 0 HcmV?d00001 diff --git a/fuzz/seeds/upload/palette.png b/fuzz/seeds/upload/palette.png new file mode 100644 index 0000000000000000000000000000000000000000..43f958dbd787ed6b4c160271ed027c02b90bcc64 GIT binary patch literal 2200 zcmaJ@`#Y3*8-HX&<&<1{+fG7@kgX?FJLIhK=3IvC(m{_Bnv63eligmeB~zB3G2;~G zwIlRO*vWCCTF=;MB8@`_hbW~%jBR`NZvKGxd(B*PeZTj8f9}uWm$~fi>87#z>(vN? zXiyJ2`@%2f%U4bL%Zq`jJ%X&L@IG|d1+M@9pa_B?2#z2Gf{@UPA}ESrD1xI1fg+@$ zjA96eAvlH*7(yz#Q5?Z=1ji8qM@YpmN+1}4-~>Vt2&uqANdzMioJ0r`Ar;VojUg}! zy-@tJ2@Zy$IEoS|N-7q^9m7x@LkSEe6+EDf;V6!y1dfslTF{LVC{CaRfszWAFpQBX zPND>fk_yrw0$2l0-~~irGpqt^0E200hdMmK!7+@$FjAoq7Q-FKF#^X(g<#+TWt_kW z0wWdrffjV*Bu0=Jsjvgw0(-y@FaQ*TM9>5xfHlwrUO)sk12kX*7)(Pu)ZqaRf#amY zN>B)k;Z6`Zsc;qq0}m(@Bu*-fhFBm6Fdm!+Yr#t}58MKKzz;A06oW({4OqY$XaX-F z0-FIEumKFFp&jb*0Ebj$23CSXSPXYk5h3IcfkVO&DP#ztK}rw{~J`N`)huC?5l6p zorf=_`0SwXj5d`06p`Dgot3e^^cwSm{r0AJEfMB{21#YOQL1%3t`ND1~U&nb&`%g{(+2uo+R%3x|Z;LcK7)y`AHJm zxZuY0XNJUSu_j3(^XN%_n*QUzBe!^F8@VJ(%7;vU9tyf1{a%!nw8*!iiOXmG$EwB(lNXFw8jFh#VWbz@#)^Bne^Iiblp|qsX6MSCXI2epByfZ(~ZAPn{M@Z z->cuhpH**Dcqf028hiH8@|Tyo0}huT442*=%x@do);<+6 zR`S)s%qNfeGxrwG>oOXun#wr)SCqvqZPekVhG-5&Rc7(81h28mn5=UT#%b{bn`g7? zGZw5Pugbb&<+W#I-`_sWs=J2^*}u7~v72Y4j0U>@b?M6{UsEE(LT@eG-A`;3`p_rZ ze}}1^nonl1U$m05)60tiz4j?f!{u2~w!uGHbk51Q{J`q8b{076XuB<2c&Nmf>^2#( z+URn#-^Kfeq1xr0D>6*Nly{@&cGlz+ zH?H?IEvOpM)<1L4M{H2f?AIMLN+|VM|IMRN%WMNHzTLhxHt}N3f>rg0ejzJ&X&tX` zVzF9o1!pF1&77=gJ8D_(q1~-V+uH7_?hd(Uh)4nnv|S=!Btb+sj8YN4Kz6>{}{e??ZfZf?UP)oS2dh9 z+_t|P5PD0eC%Md|QnuT}c+&lM-fvD<9$kMFY(={qS6zH2Bv&}s!dbU&R`^Y(tRyd_ z(9-7o%?+;@uSPrmjz8^|&5N-OqVQ>=l0TwuMGEQJDke^py{iPmS4;L%&Y#o44u5nV z>-60 zrG=brahlIMalDNCdi-5jZ{-K=mKiU4KV`yAt*^2$iji1zzb)wkz-Zb_`+5YnmX+kq0D8Owfg3-9W)9W*)CgJsEyTWJUzy%`| zi87gD7v6m)X4jQ6fqAaRl)>Thp%Z}}0^fIHbk%b4V(T8KDJgfox&02E#)nE-hTcM^ zuvWnL+U+F$^N~dR!BN_3&JdS6CY|2V8F=bQdz{DLw%dw(5}Cu&d;fD%l&KK zwB905Cn9P><}cda^?^U(=-SPA?(25zc75n~#~U-MMAl{!*kxa0lnojZJrxnL(8q0DYY>PRYEDl?6 z+_KPJV92Z--#ai>C?dm{dc03(<=%7mL^@`hW!*McMkWjHkEgtm{nstAXwyQ-!jX}2 zA>AugOZ4WBEJV%BA literal 0 HcmV?d00001 diff --git a/fuzz/seeds/upload/phone-photo-turned.jpg b/fuzz/seeds/upload/phone-photo-turned.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a1c8d5581dfe7a9635d428aecc9f35a8dca5443b GIT binary patch literal 1783 zcmbW0do-)(bobuqSLdNa3sIniBc zq9zy_85sql!YU=DRWwrrQ`&zHq#h6@fHm;KVpak%A_hyuAdP^8&WaZiVKAQtM&Dvs z9A2CtfewupRLB7_3>GVf!{YHc9GZyDjn?u=bbA74NJ{Q(C8 z!;XYUL`Fr&98XL-k(_ceHS_Gbtn)uyxOge|`i;E&g2JNWyX^9c%Bp+SHIII3{JE*Q zrM0c+X>Z@N{(buX7zd$)ppd%?Fq-oNjCViX6nIpcI9ypu3fmI944 z5YRe{fJf<`Fm+fK8tj78l|p0V}cUv}0cZ=zrASssMdu;>25pYGW5 z+E%@+OW1U6sJ$q3)WEGfE4W-IIkI$0VfYHzW+BKQd>lGz+4|zVPl)tATmG7jTGe~T z%CKcmQ+u8Yb|lz@MQc^pv{(*gDjs{=KN&}GD!T!-433f(A`sB+&*o(vtRAm5?7dkS zR2YbWDYMyFcnA_ON+%oo5Wow1_hIoq0>;<+3#jMsYs_dJWAD5%Ti?D-bv4N ztQR|~TaxwUU=zFDQOA3f$?7xcJjroOax zH^V?{s+22nv6B!sT~t_{q^l7b*T@?>#@J*pOc$-HDr8alV9f0!tT}bjs)C2-^`G&d zBfx_$d+n=ay<7bj!@X*f6i>CK?iyHI*sAja!>D4mvpa(}L`@Q!MO3tHcL!I1LA6vqDt2bRM$I zE=4Wk7nKa3fP`mQ!T`7pmA4cE=Cnw&eYS}{Wv0V%P|LQU37?qMhQB7e7qdo5^J=K( zY{~r6jqXsF@Z`gcItuERe`wd;RtrNsl_~SW64GyF=tn&1LO>=F0qLaYdqrl=Mu3hs z0+xMjmH<21t7V literal 0 HcmV?d00001 diff --git a/fuzz/seeds/upload/photo.webp b/fuzz/seeds/upload/photo.webp new file mode 100644 index 0000000000000000000000000000000000000000..dda38ad873202985233e9fbbdc92bc57b652d4ba GIT binary patch literal 486 zcmVMNk&HA0RRA3MM6+kP&gpc0RRB-3ILq}DnI}z06x)Ps7@#)BqA!f3IPBb z32Fep9Q(Wnq3yOD^xl8|pZO}EwD>}YynW!s^v!qaD$TB77&OpeX@oA9WRJD;w<}(T zb!i)}I3IZ18&CgF8jFpsVR*Oz{_b^e;!n5bhx=Xp9J@*6L;|Q*)_>GFQb0_0f1d^M z7q5JJq%TF?NS7*u{?VHZj47jh;yrMrKBY~JfRrju&H|Xu~`S4pn<6XMVAqvS3C{)=Ji7=xw3)X84-n7r|KCErt@)?r=0xx$zX@J85wAy~Unv`XuB{2Z(>}1FlzFYIC63`WA*x3-#3o?p6 z*9HRI!Spa1!7z(SQM0V;y1k669|AkZT0_pZJ#v|ebMa|;B#&UAxH95Khg@NS>N4lN z5IdJCsOIB%nm*D%XZ?Nn2FMy(k87&3rF%_)(F=NI?bP0JFR60{{R3 literal 0 HcmV?d00001 diff --git a/fuzz/seeds/upload/plain.jpg b/fuzz/seeds/upload/plain.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ae0972982a8635d185817a96efdf277bef89cd24 GIT binary patch literal 1400 zcmex=c1}I=;VrF4wW9Q)H;sz?% zD!{d!pzFb!U9xX3zTPI5o8roG<0MW4oqZMDikqloVbuf*=gfJ(V&YTRE(2~ znmD<{#3dx9RMpfqG__1j&CD$#!;7!6e%acyy{ohBw|W=v&-%I0a0~ODD)~zb z|6RPc{{{1ZhRL1(M6&8X8D;GMcK<(vgXm^&muU^j^%<|@zcBu1IC z{xdvzRNtC&(R*eYcjcTXyY3#neyilC&cCx|Tx#b{?40>yl9$=rXK7_~Jlge<_3oAY zsZM-Gmeys@Uw)dUJt^dIAZQ0Vn z{~0DucKy$=?LWgWhPAVbZgQ3??3oiCwSsrd5z z<@TK`O69-Y^}2U_P4@4ThUXvD+W*$Nwnluf+3$>uFJXpT&i|A&UH?1rKf?kkjm!2= zQm*ZP+y1X1W9`%ZchZ_sEzDdZaOl$p)j)5V(np(0?SD#|#Q)9*YUG+6Q8v$`e_;6XpTVwatLDZ<$E6nWXf-f= zVVWDv@#)y%ym!ycX8vbTR@?fYA;m}MLq>-=ldAY9gv?5s zeR}6sPR3h)Cmi3{*8h$B8h&J=x9Yz+7ydp_jl1)XYsX*T+^FcaYqu1vS7bAORXzXQ z#>vlT#qKw{*17M=l|a`F&)#MACr+-dzs>)b;i4Og?IGKLw{&e67vKEq(Yr(E-v%D= zsediXC}Df@tL^U4^>1af|25eEw3z=eti+VrtD}KYwextLZ$?;1)RW!OuVTI%?ng?0 z^0%z6|7EEERA_%_TgKYT=}EfJk~1#c`_GV>Wj=k|{IuWhQ@7e2t>49A(|`E$qHP&V M?%qAN#s2?I0JQ9HkpKVy literal 0 HcmV?d00001 diff --git a/fuzz/seeds/upload/scan-200dpi.png b/fuzz/seeds/upload/scan-200dpi.png new file mode 100644 index 0000000000000000000000000000000000000000..afb75834feab4be2a8c2a7943b5a62d5f7f19067 GIT binary patch literal 408 zcmV;J0cZY+P)o}>^~03NejRr8>;?gT(N?7F`o{h, String>| pack::pdf::Loaded { + name: "upload".into(), + content_type: content_type.into(), + kind: kind.into(), + back_of: None, + bytes, + }; + let _ = pack::pdf::sides(file(Ok(data.to_vec())), file(Err("none".into()))); +} + +/// A signed copy of an agreement: a drawn signature (a PNG, as the client +/// page takes it) or, for any other bytes, the agreement's text. +pub fn signed_copy(data: &[u8]) { + let png = files::sniff(data) == Some("image/png"); + if png && data.len() > agreements::DRAWING_LIMIT { + return; + } + let text = if png { + "# Purpose\nLanna Desk keeps your data.".to_string() + } else { + String::from_utf8_lossy(data).into_owned() + }; + let body = agreements::normalize(&text); + let sha = files::sha256_hex(body.as_bytes()); + let signed = agreements::pdf::Signed { + title: "Fuzz", + version: 1, + published: "Nov 23, 2026", + sha256: &sha, + name: "Erika Mustermann", + record: "MUSTERMANN, Erika", + at: "Nov 23, 2026, 03:00 (Chiang Mai time)", + through: "client link 1", + ip: "192.0.2.1", + user_agent: "fuzz", + drawing: png.then_some(data), + }; + let _ = agreements::pdf::render(&signed, &agreements::blocks(&body)); +} diff --git a/src/lib.rs b/src/lib.rs index 619da6f..abc873d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ pub mod documents; pub mod embedded; pub mod files; pub mod forms; +#[doc(hidden)] +pub mod fuzzing; pub mod gps; pub mod journal; pub mod legal; diff --git a/src/web/client.rs b/src/web/client.rs index b17685a..b552763 100644 --- a/src/web/client.rs +++ b/src/web/client.rs @@ -988,9 +988,6 @@ pub async fn send( // ------------------------------------------------------------ agreements -/// The largest drawn signature taken, as a PNG. -const DRAWING_LIMIT: usize = 400 * 1024; - #[derive(Debug, Default, Serialize)] struct SignForm { name: String, @@ -1085,7 +1082,7 @@ fn drawing(f: &Fields) -> Result>, &'static str> { let bytes = base64::engine::general_purpose::STANDARD .decode(b64) .map_err(|_| "The drawn signature did not arrive whole. Clear it and sign again.")?; - if bytes.len() > DRAWING_LIMIT || crate::files::sniff(&bytes) != Some("image/png") { + if bytes.len() > agreements::DRAWING_LIMIT || crate::files::sniff(&bytes) != Some("image/png") { return Err("The drawn signature did not arrive whole. Clear it and sign again."); } Ok(Some(bytes)) diff --git a/tests/fuzz_cases.rs b/tests/fuzz_cases.rs new file mode 100644 index 0000000..1d97f3c --- /dev/null +++ b/tests/fuzz_cases.rs @@ -0,0 +1,53 @@ +//! Every input a fuzzer once broke a target with, replayed on every push +//! (src/fuzzing.rs, fuzz/). A crash the nightly fuzzing finds goes into +//! `tests/fuzz_cases//` with its fix, so it can never come back. + +use std::fs; +use std::path::Path; + +#[test] +fn the_inputs_the_fuzzers_found_stay_harmless() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fuzz_cases"); + let mut tried = 0; + for (name, target) in visa::fuzzing::TARGETS { + let dir = root.join(name); + let Ok(entries) = fs::read_dir(&dir) else { + continue; + }; + for e in entries { + let path = e.unwrap().path(); + if path.extension().is_some_and(|x| x == "md") { + continue; + } + let data = fs::read(&path).unwrap(); + let caught = std::panic::catch_unwind(|| target(&data)); + assert!(caught.is_ok(), "{name}: {} breaks it again", path.display()); + tried += 1; + } + } + // the folder of every target exists, so a renamed one is noticed + for (name, _) in visa::fuzzing::TARGETS { + assert!( + root.join(name).is_dir(), + "tests/fuzz_cases/{name} is missing" + ); + } + eprintln!("{tried} fuzz cases replayed"); +} + +#[test] +fn every_target_takes_its_seeds() { + // the seeds the nightly run starts from (fuzz/seeds/) go through too + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("fuzz/seeds"); + for (name, target) in visa::fuzzing::TARGETS { + let dir = root.join(name); + let files: Vec<_> = fs::read_dir(&dir) + .unwrap_or_else(|_| panic!("fuzz/seeds/{name} is missing")) + .map(|e| e.unwrap().path()) + .collect(); + assert!(!files.is_empty(), "fuzz/seeds/{name} is empty"); + for f in files { + target(&fs::read(&f).unwrap()); + } + } +} diff --git a/tests/fuzz_cases/signed_copy/README.md b/tests/fuzz_cases/signed_copy/README.md new file mode 100644 index 0000000..2aac595 --- /dev/null +++ b/tests/fuzz_cases/signed_copy/README.md @@ -0,0 +1,2 @@ +Inputs that once broke the fuzz target `signed_copy` (src/fuzzing.rs), replayed by +`tests/fuzz_cases.rs`. Name each after what it broke. diff --git a/tests/fuzz_cases/text/README.md b/tests/fuzz_cases/text/README.md new file mode 100644 index 0000000..42a8d00 --- /dev/null +++ b/tests/fuzz_cases/text/README.md @@ -0,0 +1,2 @@ +Inputs that once broke the fuzz target `text` (src/fuzzing.rs), replayed by +`tests/fuzz_cases.rs`. Name each after what it broke. diff --git a/tests/fuzz_cases/upload/README.md b/tests/fuzz_cases/upload/README.md new file mode 100644 index 0000000..2626f4f --- /dev/null +++ b/tests/fuzz_cases/upload/README.md @@ -0,0 +1,2 @@ +Inputs that once broke the fuzz target `upload` (src/fuzzing.rs), replayed by +`tests/fuzz_cases.rs`. Name each after what it broke. diff --git a/tests/main.rs b/tests/main.rs index 428ceeb..8551c0e 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -10,6 +10,7 @@ mod common; mod companies; mod deadlines; mod documents; +mod fuzz_cases; mod garage; mod legal; mod mrz_photo;