[frameworks/kcodecs] /: [KEncodingProber] Fix GB18030 false positive
Stefan Brüns <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit d3498fd573978b3cf929f360969b992c3460b43d by Stefan Brüns.
Committed on 31/07/2026 at 07:01.
Pushed by bruns into branch 'master'.
[KEncodingProber] Fix GB18030 false positive
Although it is unlikely a random sequence fits a 4 byte GB18030 sequence
(both 2nd and 4th byte must be in the range 0x30 to 0x39), a match is
no guarantee for the string to be GB18030 encoded.
UTF-16 strings with e.g. Katakana often match this sequence, and even
strings with most ISO-8859-x or Windows single byte encodings can match
it.
M +4 -4 autotests/kencodingprobertest.cpp
M +0 -4 src/probers/nsGB2312Prober.cpp
M +1 -1 src/probers/nsMBCSSM.h
https://invent.kde.org/frameworks/kcodecs/-/commit/d3498fd573978b3cf929f360969b992c3460b43d
diff --git a/autotests/kencodingprobertest.cpp b/autotests/kencodingprobertest.cpp
index 67027ab..5bbc008 100644
--- a/autotests/kencodingprobertest.cpp
+++ b/autotests/kencodingprobertest.cpp
@@ -122,10 +122,9 @@ void KEncodingProberTest::testProbe()
QEXPECT_FAIL("utf-8 Japanese Universal", "Too low UTF-8 confidence, too high Win-1252", Abort);
QEXPECT_FAIL("Konnichiwa UTF-16LE", "Too low UTF-16LE confidence, too high Win-1252", Abort);
QEXPECT_FAIL("Konnichiwa UTF-16BE", "Too low UTF-16BE confidence, too high Win-1252", Abort);
- QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE Universal", "GB18030 false positive", Abort);
- QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE", "GB18030 false positive", Abort);
- QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16BE Universal", "GB18030 false positive", Abort);
- QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16BE", "GB18030 false positive", Abort);
+ QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE Universal", "Too low UTF-16LE confidence, too high Win-1252", Abort);
+ QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE", "MBCS filter broken", Abort);
+ QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16BE Universal", "Too low UTF-16BE confidence, too high Win-1252", Abort);
QCOMPARE(ep.encoding().toLower(), encoding);
QEXPECT_FAIL("UTF-16BE Unicode", "UTF-16 no confidence", Abort);
@@ -134,6 +133,7 @@ void KEncodingProberTest::testProbe()
QEXPECT_FAIL("UTF-16BE Unicode definite 2", "UTF-16 zero confidence", Abort);
QEXPECT_FAIL("UTF-16LE Unicode definite 2", "UTF-16 zero confidence", Abort);
QEXPECT_FAIL("utf-8 Japanese", "Too low UTF-8 confidence", Abort);
+ QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16BE", "UTF-16 zero confidence", Abort);
QCOMPARE_GE(ep.confidence(), 0.2);
}
diff --git a/src/probers/nsGB2312Prober.cpp b/src/probers/nsGB2312Prober.cpp
index 2a76543..42cf479 100644
--- a/src/probers/nsGB2312Prober.cpp
+++ b/src/probers/nsGB2312Prober.cpp
@@ -31,10 +31,6 @@ nsProbingState nsGB18030Prober::HandleData(const char *aBuf, unsigned int aLen)
mState = eNotMe;
break;
}
- if (codingState == eItsMe) {
- mState = eFoundIt;
- break;
- }
if (codingState == eStart) {
unsigned int charLen = mCodingSM->GetCurrentCharLen();
diff --git a/src/probers/nsMBCSSM.h b/src/probers/nsMBCSSM.h
index 9a65fc5..058aab1 100644
--- a/src/probers/nsMBCSSM.h
+++ b/src/probers/nsMBCSSM.h
@@ -238,7 +238,7 @@ static constexpr std::array<const unsigned char, 42> GB18030_st{
eItsMe, eItsMe, eItsMe, eItsMe, eItsMe, eItsMe, eItsMe, // eItsMe
eError, eError, eStart, 4, eError, eStart, eStart, // 3
eError, eError, eError, eError, eError, eError, 5, // 4
- eError, eError, eError, eItsMe, eError, eError, eError, // 5
+ eError, eError, eError, eStart, eError, eError, eError, // 5
// clang-format on
};