zhangchn / wiki2touch-standalone-ui

Automatically exported from code.google.com/p/wiki2touch-standalone-ui
1 stars 1 forks source link

indexer.cpp: memory bad access. #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile the indexer on snow leopard.
2. run indexer on zh dump.

What is the expected output? What do you see instead?
the indexer should end normally. but it run error on the following line.
            articlesIndex[no++] = (int) (help - articlesTitles);
value in no is greater than the size of articlesIndex array.

What version of the product are you using? On what operating system?
snow leopard. xcode 3.25

Please provide any additional information below.
after checking the source, I found the bug came from the assumption that size_t 
type is 32bit, which is not true on snow leopard xcode 3.25. It actually should 
be 64bit. 
the comment from indexer.cpp confused me a lot.
    // an entry is build like this:
    // 8 bytes block position in the file
    // 4 bytes position inside the block
    // 4 bytes length of the article
    // title in plain utf-8 coding
    // terminating zero

maybe you can fix this bug via change SIZEOF_POSITION_INFORMATION to 24 on snow 
leopard, or more appropriately set SIZEOF_POSITION_INFORMATION to 
sizeof(fpos_t)+sizeof(size_t)*2.

Original issue reported on code.google.com by simpzan on 5 Sep 2011 at 2:37

GoogleCodeExporter commented 9 years ago
maybe you can fix this bug via change SIZEOF_POSITION_INFORMATION to 24 on snow 
leopard, or more appropriately set SIZEOF_POSITION_INFORMATION to 
sizeof(fpos_t)+sizeof(size_t)*2.

this method fails. the following will succeed.

    // an entry is build like this:
    // 8 bytes block position in the file
    // 4 bytes position inside the block
    // 4 bytes length of the article
    // title in plain utf-8 coding
    // terminating zero

    fwrite(¤tBlockPos, 1, sizeof currentBlockPos, titlesFile);
    fwrite(¤tDestSize, 1, sizeof currentDestSize, titlesFile);
    fwrite(&length, 1, sizeof length, titlesFile);
    fwrite(title, 1, strlen(title)+1, titlesFile);

change variable 'currentDestSize' and 'length' to 32bit integer type like int 
in xcode environment.

Original comment by simpzan on 17 Sep 2011 at 7:19