diff options
author | Mark Felder <feld@feld.me> | 2023-12-29 14:12:44 -0500 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2023-12-29 14:12:44 -0500 |
commit | 50edef5bc13d0407aaaf26c951ce7a4a8cd4db58 (patch) | |
tree | 7a9b8bdfd6bb66988fd7f6b4330bc304967cb7ca /lib | |
parent | 8ac4458630026387a5394b427daa409b0d2667ba (diff) | |
download | pleroma-50edef5bc13d0407aaaf26c951ce7a4a8cd4db58.tar.gz pleroma-50edef5bc13d0407aaaf26c951ce7a4a8cd4db58.zip |
Change QTFastStart to recover gracefully if it encounters an error during bitstring matching
This fixes issues with internal errors when trying to serve the video
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/helpers/qt_fast_start.ex | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/pleroma/helpers/qt_fast_start.ex b/lib/pleroma/helpers/qt_fast_start.ex index 5711c7162..919fec84a 100644 --- a/lib/pleroma/helpers/qt_fast_start.ex +++ b/lib/pleroma/helpers/qt_fast_start.ex @@ -40,16 +40,21 @@ defmodule Pleroma.Helpers.QtFastStart do got_mdat, acc ) do - full_size = (size - 8) * 8 - <<data::bits-size(full_size), rest::bits>> = rest - - acc = [ - {fourcc, pos, pos + size, size, - <<size::integer-big-size(32), fourcc::bits-size(32), data::bits>>} - | acc - ] - - fix(rest, pos + size, got_moov || fourcc == "moov", got_mdat || fourcc == "mdat", acc) + try do + full_size = (size - 8) * 8 + <<data::bits-size(full_size), rest::bits>> = rest + + acc = [ + {fourcc, pos, pos + size, size, + <<size::integer-big-size(32), fourcc::bits-size(32), data::bits>>} + | acc + ] + + fix(rest, pos + size, got_moov || fourcc == "moov", got_mdat || fourcc == "mdat", acc) + rescue + _ -> + :abort + end end defp fix(<<>>, _pos, _, _, acc) do |