-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix: Fix the bug where an attempt is made to read data even after it has already been fully read. #6337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…has already been fully read.
The binary size change of libncnn.so (bytes)
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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.
Co-authored-by: Copilot <[email protected]>
Added a new parameter to the load_param function call and included additional checks for the new parameter's type and value.
|
Thanks for your contribution ! |
原逻辑:
输入流: 19="1" 20="0h" 21="1"
第一次循环 (处理
19="1"
)dr.scan("%d=", &id)
: 成功。id
设置为19
。19=
之后,指向"
。dr.scan("%15[^,\n ]", vstr)
: 成功。"1"
。vstr
被设置为"1"
。"1"
之后,指向空格。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="
。字符串拼接:
d->params[id].s = std::string(&vstr[1]) + vstr2;
std::string(&vstr[1])
的值是"1"
(去掉了开头的引号)。"1 20="
。最终处理:
d->params[19]
的s
成员被设置为字符串"1 20="
。type
被设置为7
。"0h"
的第一个"
之后,指针指向了0
。第二次循环的尝试
while (dr.scan("%d=", &id) == 1)
:0h" 21="1"
。scan
函数尝试在当前位置匹配一个整数 (%d
) 后面跟着一个等号 (=
)。0h
,这不符合%d=
的模式。scan
失败,返回0
。循环条件
dr.scan(...) == 1
为false
,整个while
循环终止。读取情况:
19 = 1 20=
20 =
21 =