mirror of
https://github.com/9001/copyparty.git
synced 2026-03-25 01:22:44 +10:00
fix au_unpk fd-leak (e.g. failed epub thumbing)
This commit is contained in:
@@ -133,6 +133,7 @@ class MParser(object):
|
|||||||
def au_unpk(
|
def au_unpk(
|
||||||
log: "NamedLogger", fmt_map: dict[str, str], abspath: str, vn: Optional[VFS] = None
|
log: "NamedLogger", fmt_map: dict[str, str], abspath: str, vn: Optional[VFS] = None
|
||||||
) -> str:
|
) -> str:
|
||||||
|
fd = 0
|
||||||
ret = ""
|
ret = ""
|
||||||
maxsz = 1024 * 1024 * 64
|
maxsz = 1024 * 1024 * 64
|
||||||
try:
|
try:
|
||||||
@@ -186,6 +187,7 @@ def au_unpk(
|
|||||||
|
|
||||||
fsz = 0
|
fsz = 0
|
||||||
with os.fdopen(fd, "wb") as fo:
|
with os.fdopen(fd, "wb") as fo:
|
||||||
|
fd = 0
|
||||||
while True:
|
while True:
|
||||||
buf = fi.read(32768)
|
buf = fi.read(32768)
|
||||||
if not buf:
|
if not buf:
|
||||||
@@ -200,6 +202,8 @@ def au_unpk(
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
if fd:
|
||||||
|
os.close(fd)
|
||||||
if ret:
|
if ret:
|
||||||
t = "failed to decompress file %r: %r"
|
t = "failed to decompress file %r: %r"
|
||||||
log(t % (abspath, ex))
|
log(t % (abspath, ex))
|
||||||
|
|||||||
Reference in New Issue
Block a user