Skip to content

export table/view/big-view/app-table to excel limit images total size - #907

Merged
freeplant merged 3 commits into
masterfrom
export-excel-limit-images-size
Aug 27, 2026
Merged

freeplant merged 3 commits into
masterfrom
export-excel-limit-images-size

Conversation

@AlexCXC

@AlexCXC AlexCXC commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@seafile-dev seafile-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:需要修改

阻塞:

  • 图片总大小限制在完整下载、临时落盘和图片解析之后才检查,无法避免本任务要消除的临时存储/内存耗尽风险(见行内评论)。

@@ -1800,6 +1804,7 @@ def add_image_to_excel(ws, cell_value, col_num, row_num, dtable_uuid, repo_id, i

response = requests.get(image_download_url)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Critical] 限制检查发生在完整下载和落盘之后

为什么重要:当前先用 requests.get() 将整张图片读入内存,并在临时目录写入文件、交给 Pillow/openpyxl 解析;直到这些操作完成后才在此处比较累计大小。因此单个超过上限的图片(或接近上限后的下一张大图)仍可占满 worker 内存和 /tmp,与本任务防止导出导致存储耗尽的目标不符;WebP 转 PNG 时还可能产生未计入 image_size 的更大临时文件。

建议修复:在创建临时文件前以流式下载执行上限校验:先校验可信的 Content-Length,并在每个 chunk 写入前按“已用额度 + 已写入字节”截断/删除;转换后应按实际待嵌入文件大小再次计数。还应为请求设置连接和读取超时。

if not value:
return None
try:
return float(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] 非有限值和零值未按参数契约处理

为什么重要:float() 会接受 naninf,随后在任务内换算字节时 int() 会抛出异常;而合法数字 0 在后续 if images_max_size else 中又被当成未传,意外回退到 100MB。设计约定非法值走默认值、合法值按传入值生效,因此这些边界值会导致导出失败或限制失效。

建议修复:解析时用 math.isfinite() 校验,并明确仅接受非负值;初始化和判断应使用 is not None 区分未传与 0。为 naninf、负数和 0 增加回归测试。

@seafile-dev seafile-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Request changes

Blocking:

  • 图片总大小检查仍发生在完整下载、临时落盘和解析之后,无法阻止单张超限图片耗尽 worker 内存或 /tmp(已有行内评论)。

Warnings:

  • images_max_size 未拒绝 nan/inf,且将 0 当作未传,违反设计中的非法值兜底与合法值生效约定(见新增行内评论)。
    Suggested fix: 校验有限且非负的数值,并用 is not None 保留 0 的语义。

@freeplant
freeplant merged commit 908d448 into master Aug 27, 2026
1 check passed
@freeplant
freeplant deleted the export-excel-limit-images-size branch August 27, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants