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

agnos updater: set decompress max_length #33320

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions system/hardware/tici/agnos.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ def __init__(self, url: str) -> None:
self.sha256 = hashlib.sha256()

def read(self, length: int) -> bytes:
while len(self.buf) < length:
self.req.raise_for_status()
while len(self.buf) < length and not self.eof:
if self.decompressor.needs_input:
self.req.raise_for_status()

try:
compressed = next(self.it)
except StopIteration:
try:
compressed = next(self.it)
except StopIteration:
self.eof = True
break
else:
compressed = b''

self.buf += self.decompressor.decompress(compressed, max_length=length)

if self.decompressor.eof:
self.eof = True
break
out = self.decompressor.decompress(compressed)
self.buf += out

result = self.buf[:length]
self.buf = self.buf[length:]
Expand Down Expand Up @@ -83,8 +90,8 @@ def unsparsify(f: StreamingDecompressor) -> Generator[bytes, None, None]:

# noop wrapper with same API as unsparsify() for non sparse images
def noop(f: StreamingDecompressor) -> Generator[bytes, None, None]:
while not f.eof:
yield f.read(1024 * 1024)
while len(chunk := f.read(1024 * 1024)) > 0:
yield chunk


def get_target_slot_number() -> int:
Expand Down
Loading