From 86cb393f7581315d5adb639d29f767779a00a0a9 Mon Sep 17 00:00:00 2001 From: blaipr Date: Mon, 24 Aug 2026 09:16:54 +0200 Subject: [PATCH] fix: the unidentifiable-upload test is not random MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `testUnidentifiableContentFallsBackToTheDeclaredType` built its payload as a fixed prefix followed by `random_bytes(48)`, and handed it to libmagic. Most of the time libmagic gives up and answers application/octet-stream, which is the inconclusive answer the test is about — the upload then falls back to the declared type and succeeds. Sometimes it does not. Measured over 3,000 payloads on this image, 16 came back as image/x-tga: about one run in two hundred. A recognised type is not inconclusive, so the declared application/pdf is not used, image/x-tga is not on the allow-list, and the upload is refused — the run fails with 400 where it wanted 200, on whichever pull request happened to be open when it landed. This is the same shape as the faker `randomNumber()` fixture already recorded here: a value drawn at random that is almost always in range, and occasionally is not. The payload is fixed now, and confirmed inconclusive. Found because it failed CI on an unrelated change, and reproduced by measuring rather than by re-running until it happened again. --- .../Api/Controllers/AccountFile/UploadControllerTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Integration/Infrastructure/Adapter/In/Api/Controllers/AccountFile/UploadControllerTest.php b/tests/Integration/Infrastructure/Adapter/In/Api/Controllers/AccountFile/UploadControllerTest.php index bd6350e1a..8e9d88ef2 100644 --- a/tests/Integration/Infrastructure/Adapter/In/Api/Controllers/AccountFile/UploadControllerTest.php +++ b/tests/Integration/Infrastructure/Adapter/In/Api/Controllers/AccountFile/UploadControllerTest.php @@ -276,6 +276,12 @@ public function testDeclaredTypeCannotLaunderIdentifiedContent(): void /** * Content the server cannot identify is still stored under the declared type: attachments * here are often keystores and certificates, which have no signature to match. + * + * The payload is fixed rather than random. It used to end in random_bytes(48), and about one + * run in two hundred produced bytes libmagic recognises — measured over 3,000 payloads on this + * image, 16 of them came back as image/x-tga. A recognised type is not the inconclusive answer + * this test is about, and image/x-tga is not on the allow-list, so the upload was refused and + * the run failed with 400 where it wanted 200, on whichever pull request happened to be open. */ public function testUnidentifiableContentFallsBackToTheDeclaredType(): void { @@ -283,7 +289,7 @@ public function testUnidentifiableContentFallsBackToTheDeclaredType(): void $r = $this->upload($accountId, [ 'name' => 'blob.pdf', - 'content' => base64_encode("\x00\x01\x02\xff\xfe" . random_bytes(48)), + 'content' => base64_encode("\x00\x01\x02\xff\xfe" . str_repeat("\x13\x37", 24)), 'type' => 'application/pdf', 'extension' => 'PDF', ]);