Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite loop on corrupt stream recording #96881

Merged
merged 2 commits into from Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/stream/fmp4utils.py
Expand Up @@ -151,7 +151,7 @@ def find_moov(mp4_io: BufferedIOBase) -> int:
while 1:
mp4_io.seek(index)
box_header = mp4_io.read(8)
if len(box_header) != 8:
if len(box_header) != 8 or box_header[0:4] == b"\x00\x00\x00\x00":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a general note, this looks like something that should be in a separate library, not in Home Assistant Core 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've discussed moving this out of core, and I think we generally agreed it makes sense, but haven't made the plan in more detail or executed on it yet.

raise HomeAssistantError("moov atom not found")
if box_header[4:8] == b"moov":
return index
Expand Down
2 changes: 1 addition & 1 deletion tests/components/stream/test_worker.py
Expand Up @@ -245,7 +245,7 @@ def mux(self, packet):
# Forward to appropriate FakeStream
packet.stream.mux(packet)
# Make new init/part data available to the worker
self.memory_file.write(b"\x00\x00\x00\x00moov")
self.memory_file.write(b"\x00\x00\x00\x08moov")

def close(self):
"""Close the buffer."""
Expand Down