Repository: goldendict/goldendict (language: cpp)

Issue:
Please update goldendict/blob/master/mdictparser.cc#L622
GoldenDict would break with these PNG images（keyword：OPEU4_0002）:  **[test.zip](https://github.com/goldendict/goldendict/files/12767768/test.zip)**

More discuss： https://forum.freemdict.com/t/topic/23713

Advise：

From：[goldendict/goldendict/blob/master/mdictparser.cc#L622](https://github.com/goldendict/goldendict/blob/master/mdictparser.cc#L622)

to：[xiaoyifang/goldendict-ng/blob/staged/src/dict/mdictparser.cc#L559](https://github.com/xiaoyifang/goldendict-ng/blob/staged/src/dict/mdictparser.cc#L559)


Discussion / hints:
> More discuss： https://forum.freemdict.com/t/topic/23713

How about a short version of the discussion's conclusions in English?
Summary of the discussion:

Experimentation was conducted to determine the cause of the program crashing. Different symptoms were observed when the number of images in the case was increased or decreased, indicating that there is a problem.

There are two non-professional speculations that have a certain probability of solving the problem: (1) There might be an issue with image processing. All images should be processed using a more professional software like Photoshop, rather than other ones. (2) There might be a problem with the image file names. If a file name contains an underscore, the first half before the underscore should not contain numbers.

Response from an expert: Programmers discussed this issue two or three years ago. The above-mentioned speculations and solutions are mere luck, and the real problem lies in the encoding of GoldenDict. The "endPos" in goldendict/goldendict/blob/master/mdictparser.cc#L622 should be changed to "shadowEndPos".

Fix patch:
diff --git a/mdictparser.cc b/mdictparser.cc
index c2b1141ab..9762fee20 100644
--- a/mdictparser.cc
+++ b/mdictparser.cc
@@ -521,12 +521,11 @@ bool MdictParser::readRecordBlockInfos()
     r.compressedSize = readNumber( in );
     r.decompressedSize = readNumber( in );
     r.startPos = acc1;
-    r.endPos = acc1 + r.compressedSize;
     r.shadowStartPos = acc2;
     r.shadowEndPos = acc2 + r.decompressedSize;
     recordBlockInfos_.push_back( r );
 
-    acc1 = r.endPos;
+    acc1 += r.compressedSize;
     acc2 = r.shadowEndPos;
   }
 
@@ -619,7 +618,7 @@ bool MdictParser::readRecordBlock( MdictParser::HeadWordIndex & headWordIndex,
 
   for ( HeadWordIndex::const_iterator i = headWordIndex.begin(); i != headWordIndex.end(); ++i )
   {
-    if ( recordBlockInfos_[idx].endPos <= i->first )
+    if ( recordBlockInfos_[idx].shadowEndPos <= i->first )
       idx = RecordIndex::bsearch( recordBlockInfos_, i->first );
 
     if ( idx == ( size_t )( -1 ) )
diff --git a/mdictparser.hh b/mdictparser.hh
index b8dee43e4..01daf25be 100644
--- a/mdictparser.hh
+++ b/mdictparser.hh
@@ -74,7 +74,6 @@ public:
   struct RecordIndex
   {
     qint64 startPos;
-    qint64 endPos;
     qint64 shadowStartPos;
     qint64 shadowEndPos;
     qint64 compressedSize;
diff --git a/mdx.cc b/mdx.cc
index f9d577e6a..8595d59d0 100644
--- a/mdx.cc
+++ b/mdx.cc
@@ -65,7 +65,7 @@ using namespace Mdict;
 enum
 {
   kSignature = 0x4349444d,  // MDIC
-  kCurrentFormatVersion = 11 + BtreeIndexing::FormatVersion + Folding::Version
+  kCurrentFormatVersion = 12 + BtreeIndexing::FormatVersion + Folding::Version
 };
 
 DEF_EX( exCorruptDictionary, "dictionary file was tampered or corrupted", std::exception )


Test patch: