-
Notifications
You must be signed in to change notification settings - Fork 118
Open
Labels
bugSomething isn't workingSomething isn't working
Description
问题说明
目前在下载完文件时,如果这个文件大于512字节,会尝试对其末尾512字节使用pickle.loads函数进行解析,如果未曾编码过,在特定文件内容时,这个函数有可能会造成大量调用内存,比如下面这个例子中会占用34G的内存。
示例
示例文件网盘链接:https://fzls.lanzoui.com/iwnVktkr9je
若链接失效,可直接下载附件文件自行上传后得到新的链接
示例代码
lzy = LanZouCloud()
lzy.down_file_by_url("https://fzls.lanzoui.com/iwnVktkr9je")修复办法
api/utils.py中增加开关,比如直接复用self._limit_mode,从而在确定不会使用额外编码来绕开官方限制的情况下(不调用ignore_limits的情况下)不会尝试使用pickle解析文件末尾512字节
原来代码
def un_serialize(data: bytes):
"""反序列化文件信息数据"""
try:
ret = pickle.loads(data)
if not isinstance(ret, dict):
return None
return ret
except Exception: # 这里可能会丢奇怪的异常
return None调整后代码
def un_serialize(data: bytes, _limit_mode: bool):
"""反序列化文件信息数据"""
try:
if _limit_mode:
# 不尝试从文件末尾解析额外编码进去的信息
return None
ret = pickle.loads(data)
if not isinstance(ret, dict):
return None
return ret
except Exception: # 这里可能会丢奇怪的异常
return NoneMetadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
