Close file handle on error

This commit is contained in:
Andrew Murray 2025-03-30 23:31:31 +11:00
parent 14fb62e36c
commit eea2f99728

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: