Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,12 +1208,29 @@ QVector<QPair<QString, QStringList>> Utils::getSupportEncoding()
qDebug() << "readStream.readLine()";
QString group = readStream.readLine();

Copy link
Copy Markdown

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.

Suggested change
QString group = readStream.readLine();
QString group = readStream.readLine().trimmed();

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Any line containing = is accepted as the encoding entry, including =UTF-8 or unrelated keys such as comment=...; the code never validates that the key portion is nonempty or is the expected encoding key, so malformed or unrelated entries become supported encodings.

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
int eqIdx = encodes.indexOf('=');
if (eqIdx == -1) {
qWarning() << "unexpected encodes line, skipped:" << encodes;
continue;
}
QString value = encodes.mid(eqIdx + 1).trimmed();
int eqIdx = encodes.indexOf('=');
if (eqIdx == -1) {
qWarning() << "unexpected encodes line, skipped:" << encodes;
continue;
}
QString encodeKey = encodes.left(eqIdx).trimmed();
if (encodeKey.isEmpty() || encodeKey != "encodes") {
qWarning() << "unexpected encodes key, skipped:" << encodes;
continue;
}
QString value = encodes.mid(eqIdx + 1).trimmed();

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;
Expand Down
Loading