Skip to content

Conversation

futz12
Copy link
Contributor

@futz12 futz12 commented Sep 30, 2025

原逻辑:

输入流: 19="1" 20="0h" 21="1"

第一次循环 (处理 19="1")

  1. dr.scan("%d=", &id): 成功。

    • id 设置为 19
    • 输入流指针移动到 19= 之后,指向 "
  2. dr.scan("%15[^,\n ]", vstr): 成功。

    • 它读取不包含空格的字符串,所以它只读取了 "1"
    • vstr 被设置为 "1"
    • 输入流指针移动到 "1" 之后,指向空格。
  3. is_string 分支:

    • vstr_is_string(vstr) 因为 " 开头而返回 true
    • vstr[0] == '"'true
    • 执行 nscan = dr.scan("%255[^\"\n]\"", vstr2)
    • 这是关键点
      • 此时的输入流是 20="0h" 21="1" (从空格开始)。
      • 格式串 [^\"\n] 会匹配任何不是 "\n 的字符
      • 因此,它会贪婪地读取 20=
      • 当它读到 "0h" 的第一个 " 时,[^\"\n] 的匹配停止。
      • 此时,格式串的下一部分要求输入流中必须有一个 " 来作为结束符。当前输入流的字符恰好就是 "
      • 匹配成功!
    • nscan 的值是 1
    • vstr2 被设置为字符串 " 20="
  4. 字符串拼接:

    • 代码执行 d->params[id].s = std::string(&vstr[1]) + vstr2;
    • std::string(&vstr[1]) 的值是 "1" (去掉了开头的引号)。
    • 拼接后的结果是 "1 20="
  5. 最终处理:

    • d->params[19]s 成员被设置为字符串 "1 20="
    • 它的 type 被设置为 7
    • 此时,输入流已经被消耗到了 "0h" 的第一个 " 之后,指针指向了 0

第二次循环的尝试

  1. while (dr.scan("%d=", &id) == 1):

    • 此时的输入流是 0h" 21="1"
    • scan 函数尝试在当前位置匹配一个整数 (%d) 后面跟着一个等号 (=)。
    • 输入流的开头是 0h,这不符合 %d= 的模式。
    • scan 失败,返回 0
  2. 循环条件 dr.scan(...) == 1false整个 while 循环终止

读取情况:
19 = 1 20=
20 =
21 =

@github-actions github-actions bot added the core label Sep 30, 2025
Copy link

github-actions bot commented Sep 30, 2025

The binary size change of libncnn.so (bytes)

architecture base size pr size difference
x86_64 15159560 15159560 0 😘
armhf 6182416 6186432 +4016 ⚠️
aarch64 9454784 9521008 +66224 ⚠️

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.57%. Comparing base (22aba56) to head (b0d970b).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6337      +/-   ##
==========================================
- Coverage   95.90%   95.57%   -0.33%     
==========================================
  Files         840      840              
  Lines      265637   260958    -4679     
==========================================
- Hits       254747   249408    -5339     
- Misses      10890    11550     +660     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nihui nihui requested a review from Copilot September 30, 2025 15:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes a bug in string parsing logic where the scanner would continue reading input data even after a string had already been fully consumed. The issue occurred when a quoted string was complete (ending with a quote) but the parser would attempt to scan for additional content, causing it to consume data from subsequent parameters.

  • Adds validation to check if a quoted string is already complete before scanning for additional content
  • Prevents over-consumption of input data that should belong to subsequent parameters

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

futz12 and others added 2 commits October 4, 2025 19:20
Added a new parameter to the load_param function call and included additional checks for the new parameter's type and value.
@github-actions github-actions bot added the test label Oct 11, 2025
@tencent-adm
Copy link
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ futz12
❌ nihui
You have signed the CLA already but the status is still pending? Let us recheck it.

@nihui nihui merged commit 611275b into Tencent:master Oct 11, 2025
101 of 108 checks passed
@nihui
Copy link
Member

nihui commented Oct 11, 2025

Thanks for your contribution !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants