Skip to content

fix(pdf): use UUID-only backup filename to avoid NAME_MAX overflow - #294

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-370563-fix-long-filename-save-failure
Jul 20, 2026
Merged

fix(pdf): use UUID-only backup filename to avoid NAME_MAX overflow#294
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-370563-fix-long-filename-save-failure

Conversation

@add-uos

@add-uos add-uos commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

When saving files with very long filenames (especially with CJK characters that expand in UTF-8), the backup path
".{filename}.backup.{uuid}" could exceed the filesystem's NAME_MAX limit of 255 bytes per path component, causing save failures. Use a UUID-only hidden filename (".{uuid}") as backup, which is always 39 bytes and avoids the issue entirely.

使用纯UUID作为备份文件名,避免超长文件名导致的NAME_MAX溢出问题。
当保存带有超长文件名(特别是CJK字符在UTF-8中占多字节)的文件时,
原有的备份路径".{filename}.backup.{uuid}"可能超过文件系统的
NAME_MAX限制(255字节),导致保存失败。改为仅使用UUID作为隐藏
备份文件名(".{uuid}"),固定39字节,彻底避免此问题。

Log: 修复超长文件名保存失败问题
PMS: BUG-370563
Influence: 修复后带有超长文件名的PDF文档编辑后可正常保存,中英文混合文件名也能正常处理。

Summary by Sourcery

Ensure PDF saving uses UUID-only temporary and backup filenames to avoid filesystem NAME_MAX overflows with very long filenames.

Bug Fixes:

  • Prevent save failures for PDFs with very long or multi-byte filenames by replacing filename-based backup paths with fixed-length UUID-only hidden backup files.

Enhancements:

  • Standardize temporary and backup file UUIDs to omit braces for consistent, compact file naming.
  • Update SPDX copyright header years for the PDF document implementation file.

When saving files with very long filenames (especially with CJK
characters that expand in UTF-8), the backup path
".{filename}.backup.{uuid}" could exceed the filesystem's
NAME_MAX limit of 255 bytes per path component, causing save
failures. Use a UUID-only hidden filename (".{uuid}") as backup,
which is always 39 bytes and avoids the issue entirely.

使用纯UUID作为备份文件名,避免超长文件名导致的NAME_MAX溢出问题。
当保存带有超长文件名(特别是CJK字符在UTF-8中占多字节)的文件时,
原有的备份路径".{filename}.backup.{uuid}"可能超过文件系统的
NAME_MAX限制(255字节),导致保存失败。改为仅使用UUID作为隐藏
备份文件名(".{uuid}"),固定39字节,彻底避免此问题。

Log: 修复超长文件名保存失败问题
PMS: BUG-370563
Influence: 修复后带有超长文件名的PDF文档编辑后可正常保存,中英文混合文件名也能正常处理。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了备份文件名过长导致保存失败的问题,逻辑清晰且无安全漏洞
修改合理且注释完善,仅因非功能性改动保留少量扣分空间

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修改位于 dpdfdoc.cppDPdfDoc::save() 函数中。原代码拼接完整文件名和带花括号的 UUID 极易超过 255 字节限制,修改后仅使用不带花括号的 UUID 作为隐藏备份文件名,有效避免了 QFile::rename 失败的问题。临时文件路径也同步去除了花括号。
潜在问题:无
建议:无需额外修改

  • 2.代码质量(良好)✓

代码修改精简,注释从原先的描述性说明更新为解释修改原因(避免 NAME_MAX 限制),提高了代码可读性和可维护性。
潜在问题:无
建议:无需额外修改

  • 3.代码性能(无性能问题)✓

UUID 生成和字符串拼接操作开销极小,不影响整体性能。
潜在问题:无
建议:无需额外修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入任何安全风险,UUID 的使用保证了文件名的唯一性,且未涉及外部输入拼接,无注入风险。

  • 建议:无需额外修改

■ 【改进建议代码示例】

// 当前代码已足够完善,无需进一步修改

@sourcery-ai

sourcery-ai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts PDF saving logic to use brace-less UUID filenames for temporary and backup files, ensuring hidden backup names no longer depend on potentially overlong original filenames and thus avoid filesystem NAME_MAX overflows, while updating the file copyright range.

Sequence diagram for updated DPdfDoc::save temporary and backup filename handling

sequenceDiagram
    actor User
    participant DPdfDoc
    participant QTemporaryDir
    participant QUuid
    participant QFileInfo
    participant QFile

    User->>DPdfDoc: save()
    DPdfDoc->>QTemporaryDir: QTemporaryDir()
    DPdfDoc->>QUuid: createUuid()
    QUuid-->>DPdfDoc: uuid
    DPdfDoc->>QUuid: toString(WithoutBraces)
    QUuid-->>DPdfDoc: tempUuidString
    DPdfDoc->>DPdfDoc: build tempFilePath from tempDir.path() and tempUuidString

    DPdfDoc->>DPdfDoc: targetPath = d_func()->m_filePath
    DPdfDoc->>QFileInfo: QFileInfo(targetPath)
    QFileInfo-->>DPdfDoc: fileInfo
    DPdfDoc->>fileInfo: absolutePath()
    fileInfo-->>DPdfDoc: dirPath
    DPdfDoc->>QUuid: createUuid()
    QUuid-->>DPdfDoc: backupUuid
    DPdfDoc->>QUuid: toString(WithoutBraces)
    QUuid-->>DPdfDoc: backupUuidString
    DPdfDoc->>DPdfDoc: build backupPath as dirPath + "/." + backupUuidString

    DPdfDoc->>QFile: QFile(targetPath)
    DPdfDoc->>QFile: rename(targetPath, backupPath)
    DPdfDoc->>QFile: saveWriter.write(tempFilePath, targetPath)
    DPdfDoc-->>User: return true/false
Loading

File-Level Changes

Change Details Files
Use brace-less UUIDs for temporary and backup file paths to avoid NAME_MAX issues with long filenames when saving PDFs.
  • Change temporary PDF save path to use QUuid::createUuid().toString(QUuid::WithoutBraces) so the temp filename is short and predictable in length.
  • Replace backup file naming scheme from one that included the original filename and extra suffixes to a hidden file named only by a UUID, decoupling backup path length from the user filename and guaranteeing it stays within NAME_MAX.
  • Update surrounding comments to document the UUID-only hidden backup strategy and its motivation related to NAME_MAX limits.
3rdparty/deepin-pdfium/src/dpdfdoc.cpp
Update project metadata in the PDF document source file.
  • Extend SPDX-FileCopyrightText year range from 2023 to 2023 - 2026.
3rdparty/deepin-pdfium/src/dpdfdoc.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Sorry @add-uos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos

add-uos commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 00ff07e into linuxdeepin:master Jul 20, 2026
12 checks passed
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