Repository navigation
fix: parse encodes.ini by structure instead of fixed offsets #633
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1208,12 +1208,29 @@ QVector<QPair<QString, QStringList>> Utils::getSupportEncoding() | |||||||||||||||||||||||||||||||||||
| qDebug() << "readStream.readLine()"; | ||||||||||||||||||||||||||||||||||||
| QString group = readStream.readLine(); | ||||||||||||||||||||||||||||||||||||
| qDebug() << "group:" << group; | ||||||||||||||||||||||||||||||||||||
| QString key = group.mid(1, group.length() - 2); | ||||||||||||||||||||||||||||||||||||
| if (!group.startsWith('[') || !group.endsWith(']')) { | ||||||||||||||||||||||||||||||||||||
| qWarning() << "unexpected group line, skipped:" << group; | ||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| QString key = group.mid(1, group.length() - 2).trimmed(); | ||||||||||||||||||||||||||||||||||||
| QString encodes = readStream.readLine(); | ||||||||||||||||||||||||||||||||||||
| qDebug() << "encodes:" << encodes; | ||||||||||||||||||||||||||||||||||||
| QString value = encodes.mid(8, encodes.length() - 2); | ||||||||||||||||||||||||||||||||||||
| int eqIdx = encodes.indexOf('='); | ||||||||||||||||||||||||||||||||||||
| if (eqIdx == -1) { | ||||||||||||||||||||||||||||||||||||
| qWarning() << "unexpected encodes line, skipped:" << encodes; | ||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| QString value = encodes.mid(eqIdx + 1).trimmed(); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
1216
to
+1223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (broader_impact): The parser unconditionally consumes the line after every valid group as its value line. If a group has no key-value line and the next line is another group, that next group is consumed and skipped; its following value line is then treated as a group and skipped as well, so one malformed group causes the subsequent valid group to disappear. Triggers: When encodes.ini contains a section without a value line before the next section. Suggested fix: Parse input line-by-line and retain a pending section until a valid key-value line is encountered, rather than consuming the next line unconditionally.
Comment on lines
+1218
to
+1223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Any line containing Triggers: When encodes.ini contains malformed or unrelated key-value lines. Suggested fix: Validate the key portion before accepting the value, and reject empty keys or keys that are not the supported-encoding entry.
Suggested change
|
||||||||||||||||||||||||||||||||||||
| QStringList encodeNames; | ||||||||||||||||||||||||||||||||||||
| const QStringList parts = value.split(',', Qt::SkipEmptyParts); | ||||||||||||||||||||||||||||||||||||
| for (const QString &part : parts) { | ||||||||||||||||||||||||||||||||||||
| const QString name = part.trimmed(); | ||||||||||||||||||||||||||||||||||||
| if (!name.isEmpty()) { | ||||||||||||||||||||||||||||||||||||
| encodeNames.append(name); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| qDebug() << "value:" << value; | ||||||||||||||||||||||||||||||||||||
| tmpEncodeVec.append(QPair<QString, QStringList>(key, value.split(","))); | ||||||||||||||||||||||||||||||||||||
| tmpEncodeVec.append(QPair<QString, QStringList>(key, encodeNames)); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| qDebug() << "tmpEncodeVec:" << tmpEncodeVec; | ||||||||||||||||||||||||||||||||||||
| s_groupEncodeVec = tmpEncodeVec; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
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.
issue (bug_risk): A section line with leading or trailing whitespace is skipped because validation checks the raw line for
[and]before trimming it. The parser therefore drops otherwise structurally valid groups such as[Unicode]instead of normalizing them.Triggers: When encodes.ini contains whitespace around a section header.
Suggested fix: Trim the section line before checking its delimiters, or allow surrounding whitespace in the validation.