Commit 9233d5c
fix: parse HTTP Range header correctly in output_file() fixes ZoneMinder#4777
The previous implementation used `str_replace($range, '-', $range)` which
is a no-op (wrong arg order, return value discarded), then cast the raw
Range value (e.g. "12345-67890" or "-500") to int. The function then
ignored the requested END entirely and always streamed from the parsed
start to EOF.
For a suffix range like `Range: bytes=-500` -- which Chrome's media stack
sends to locate the moov atom in many HEVC mp4s -- (int)"-500" is -500,
producing Content-Length = filesize + 500. fseek with SEEK_SET fails for
negative offsets, so the body delivered was filesize bytes against an
inflated Content-Length, triggering ERR_CONTENT_LENGTH_MISMATCH in the
browser and blocking HEVC playback in the files view.
Parse `bytes=start-end`, `bytes=start-`, and `bytes=-suffix` per RFC 7233,
clamp the end to file size, return 416 for unsatisfiable ranges, set
Content-Length to the actual byte count served, and stop reading once
that many bytes have been emitted. Guard ob_flush() with ob_get_level()
so it does not warn when no buffer is active.
Verified on pseudo by loading an HEVC mp4 in Chrome -- the
ERR_CONTENT_LENGTH_MISMATCH is gone, the browser parses metadata
(duration, dimensions) and buffers playback data normally.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 97dd74d commit 9233d5c
1 file changed
Lines changed: 36 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2367 | 2367 | | |
2368 | 2368 | | |
2369 | 2369 | | |
2370 | | - | |
2371 | 2370 | | |
| 2371 | + | |
| 2372 | + | |
2372 | 2373 | | |
2373 | 2374 | | |
2374 | | - | |
2375 | | - | |
2376 | | - | |
2377 | | - | |
2378 | | - | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
2379 | 2395 | | |
2380 | | - | |
2381 | | - | |
| 2396 | + | |
| 2397 | + | |
2382 | 2398 | | |
2383 | | - | |
2384 | | - | |
2385 | | - | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
2386 | 2402 | | |
2387 | 2403 | | |
2388 | 2404 | | |
| |||
2391 | 2407 | | |
2392 | 2408 | | |
2393 | 2409 | | |
2394 | | - | |
| 2410 | + | |
2395 | 2411 | | |
2396 | | - | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
2397 | 2415 | | |
2398 | | - | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
2399 | 2419 | | |
2400 | | - | |
| 2420 | + | |
| 2421 | + | |
2401 | 2422 | | |
2402 | 2423 | | |
2403 | 2424 | | |
| |||
0 commit comments