resize --output . silently overwrites and destroys the source image

未关闭
#25 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
cli

调研方向

从 ipro resize 入口开始,使用 orig.jpg --width 400 --output . 重现冲突。跟踪写入前输入路径和输出路径的解析过程;完成标准是:除非实现了文档中说明的强制行为,否则对于相同的已解析路径应以明确的错误拒绝,同时源文件保持不变。

由索引模型根据 Issue 内容生成。

描述

ipro resize writes its output using the same basename as the input and relies
on the output directory to keep the two apart. When --output points at the
directory the source already lives in, the resized file lands on top of the
original and destroys it. There is no warning, no prompt, and no error. The
success line even reports the overwritten path as if it were a new file.

The original is unrecoverable.

Reproduction

ipro-cli 1.6.0, Python 3.14.3, macOS 26.6.

$ magick -size 2000x1000 gradient:navy-orange orig.jpg
$ magick identify -format '%wx%h %[size]' orig.jpg
2000x1000 75631B

$ ipro resize orig.jpg --width 400 --output .
✓ Created: orig.jpg (400x200, 3 KB)

Successfully created 1 image(s) from orig.jpg

$ magick identify -format '%wx%h %[size]' orig.jpg
400x200 3080B

$ ls
orig.jpg

The 2000x1000 source is gone. One file remains, and it is the 400px derivative.

What works

The default path is safe. With no --output, the resized copy goes to
resized-400w/ and the source is untouched:

$ ipro resize orig2.jpg --width 400
$ ls
orig2.jpg  resized-400w/
$ magick identify -format '%wx%h' orig2.jpg
2000x1000

So the hazard is specific to --output resolving to the source file's own
directory. . is the obvious way to hit it, but any equivalent path does the same
thing.

How I hit it

Prepping two hero images for a blog post. I cropped the sources, then ran
ipro resize cropped.jpeg --width 1200 --quality 82 --output . intending to write
1200px versions beside the crops. It consumed the crops instead. I happened to
have kept the pre-crop originals, so nothing was actually lost, but only by luck.
A one-command ipro resize photo.jpg --width 1200 --output . on an irreplaceable
photo is unrecoverable.

Expected

Refuse to write when the resolved output path equals the resolved input path.
Something like:

error: output path is the same as the input (orig.jpg).
       Use a different --output directory, or pass --force to overwrite.

Possible fixes

  1. Guard the collision. Compare resolved input and output paths before
    writing; abort unless an explicit --force is given. Smallest change, fixes
    the data loss, keeps current behavior available for anyone who wants it.
  2. Put the size in the filename when the output directory is not the
    generated resized-* one, e.g. orig-400w.jpg. This removes the collision
    rather than guarding it, and makes --output . do the useful thing people
    probably expect. Related to the naming discussion in #21.
  3. Both: name the file by size, and still refuse an exact path collision.

I'd suggest 1 on its own as a fast fix, since it turns silent data loss into a
clear error, and 2 as the better long-term behavior.

Happy to open a PR for the guard if that's useful.

— Emily

主要语言
Python
星标
1
派生
0
平均合并
4 小时 13 分钟
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cadentdev/ipro 的其他 Issue

查看 cadentdev/ipro 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。