Close file handle on error (#8846)

This commit is contained in:
Andrew Murray 2025-03-31 05:16:50 +11:00 committed by GitHub
parent 81be8d5410
commit f673f3e543
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,12 +35,16 @@ class TarIO(ContainerIO.ContainerIO[bytes]):
while True:
s = self.fh.read(512)
if len(s) != 512:
self.fh.close()
msg = "unexpected end of tar file"
raise OSError(msg)
name = s[:100].decode("utf-8")
i = name.find("\0")
if i == 0:
self.fh.close()
msg = "cannot find subfile"
raise OSError(msg)
if i > 0: