Skip to content

fix: Fix url link access#16

Merged
lzwind merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix
Oct 15, 2025
Merged

fix: Fix url link access#16
lzwind merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Oct 15, 2025

Increase URI buffer size for longer URLs .

Log: Fix url link access.
Bug: https://pms.uniontech.com/bug-view-335729.html

lzwind
lzwind previously approved these changes Oct 15, 2025
Increase URI buffer size for longer URLs .

Log: Fix url link access.
Bug: https://pms.uniontech.com/bug-view-335729.html
@github-actions
Copy link

TAG Bot

TAG: 1.5.4
EXISTED: no
DISTRIBUTION: unstable

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码审查提供改进意见:

  1. 代码安全性改进:
  • 当前代码使用了固定大小的字符数组来存储URI,虽然已经从256增加到2048,但这仍然可能不足以处理所有情况。
  • 建议使用std::string或动态内存分配来处理任意长度的URI,避免缓冲区溢出的风险。
  • 对于外部输入的URI,应该进行有效性验证,防止恶意链接或协议攻击。
  1. 代码逻辑改进:
  • 变量名"lenth"拼写错误,应该是"length"。
  • 没有检查FPDFAction_GetURIPath的返回值是否成功,仅检查了长度是否为0。
  • 建议添加对uri内容的有效性检查,确保它是合法的URL格式。
  1. 代码性能改进:
  • 如果频繁调用此函数,可以考虑缓存URI结果。
  • 对于大型PDF文件,可能需要考虑异步加载机制。
  1. 代码质量改进:
  • 建议添加适当的错误处理和日志记录。
  • 可以添加注释说明URI处理的用途和限制。
  • 考虑使用现代C++的特性,如智能指针和RAII。

改进后的代码建议:

bool DPdfPagePrivate::loadAnnots()
{
    // ... 其他代码 ...

    //获取类型
    if (PDFACTION_URI == type) {
        try {
            std::vector<char> uri(2048); // 使用动态缓冲区
            unsigned long length = FPDFAction_GetURIPath(m_doc, action, uri.data(), uri.capacity());
            
            // 检查API调用是否成功
            if (length > 0 && length < uri.capacity()) {
                std::string uriStr(uri.data(), length);
                
                // 验证URI格式
                if (isValidUri(uriStr)) {
                    dAnnot->setUrl(uriStr);
                } else {
                    LOG(WARNING) << "Invalid URI format in PDF annotation";
                }
            } else if (length >= uri.capacity()) {
                // URI过长,需要更大的缓冲区
                LOG(ERROR) << "URI exceeds maximum buffer size";
            }
        } catch (const std::exception& e) {
            LOG(ERROR) << "Error processing URI: " << e.what();
        }
    }

    // ... 其他代码 ...
}

// 添加URI验证函数
bool DPdfPagePrivate::isValidUri(const std::string& uri) {
    // 实现URI验证逻辑
    // 检查协议是否允许(如http, https等)
    // 检查字符集是否合法
    // 其他安全检查...
    return true;
}

这些改进可以提高代码的安全性、可靠性和可维护性。同时,通过添加适当的错误处理和日志记录,可以更好地调试和监控可能出现的问题。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

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

@lzwind lzwind merged commit eccf18c into linuxdeepin:master Oct 15, 2025
16 of 18 checks passed
@re2zero re2zero deleted the bugfix branch October 15, 2025 05:41
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