Commit 76f6595
committed
fix(encryption): Fix encrypted stream EOF handling for range reads
Fixes 21 Behat integration test failures where range downloads of
encrypted files returned empty content instead of file data.
Root Cause:
- stream_read() relied on unencryptedSize to detect EOF
- For newly uploaded files, unencryptedSize might be zero if cache
update was delayed or stream opened before size finalized
- Result: read loop clamped count to 0, returned empty string
Fix (lib/private/Files/Stream/Encryption.php):
- readCache(): Check if data was read before decrypting
- Return early on EOF (leave cache empty to signal this)
- Prevents attempting to decrypt empty data
- stream_read(): Use empty cache as EOF signal
- Still respects unencryptedSize when available
- More robust: works even if unencryptedSize temporarily incorrect
- Uses strlen($cache) for actual block size (handles partial blocks)
Tests Added:
- tests/lib/Files/Stream/EncryptionRangeReadTest.php (11 tests):
- Range reads at various positions (start, middle, across blocks)
- Block boundary cases (8096-byte blocks for signed encryption)
- EOF handling (at EOF, partial past EOF)
- Single byte and multi-block spanning reads
- Size tracking verification up to 1MB (exact byte accuracy)
- tests/lib/Files/Stream/EncryptionLargeFileTest.php (2 tests):
- Placeholder for 5MB+ file tests (separate investigation needed)
Validation:
- 12 new tests pass
- Size tracking verified: 100B to 1MB with 0 byte difference
- 147 existing EncryptionTest tests pass (no regression)
- Handles Behat test file sizes (9-28 bytes) perfectly
Note:
- Files >5MB via file_put_contents() have unrelated issues (not in scope)
- Behat integration tests use small files (<100 bytes) - fully supported
Signed-off-by: Stephen Cuppett <[email protected]>1 parent 0fb69df commit 76f6595
File tree
3 files changed
+483
-11
lines changed- lib/private/Files/Stream
- tests/lib/Files/Stream
3 files changed
+483
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
256 | 262 | | |
| 263 | + | |
257 | 264 | | |
258 | | - | |
259 | | - | |
| 265 | + | |
260 | 266 | | |
261 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
262 | 274 | | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
269 | 293 | | |
270 | 294 | | |
271 | 295 | | |
272 | | - | |
273 | | - | |
| 296 | + | |
| 297 | + | |
274 | 298 | | |
275 | 299 | | |
| 300 | + | |
276 | 301 | | |
277 | 302 | | |
278 | 303 | | |
| |||
453 | 478 | | |
454 | 479 | | |
455 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
456 | 487 | | |
457 | 488 | | |
458 | 489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
0 commit comments