vineet2010211 / blockchain

Automatically exported from code.google.com/p/blockchain
0 stars 0 forks source link

segfault on OS X near the end of the data #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Build on OSX
2. run

What is the expected output? What do you see instead?
Expect everything to be parsed.

See segfault.

... much trimmed
Successfully opened block-chain input file '/Users/bruce/Library/Application 
Support/Bitcoin/blocks/blk00104.dat'
Scanned 277,415 block headers so far, 819 since last time.
Successfully opened block-chain input file '/Users/bruce/Library/Application 
Support/Bitcoin/blocks/blk00105.dat'
Scanned 278,284 block headers so far, 869 since last time.
Warning: Missing block-header; scanning for next one.
Process 32116 stopped
* thread #1: tid = 0x4b6280, 0x000000010000dc04 
blockchain.out`BlockChainImpl::readBlockHeader(this=0x0000000101000000) + 310 
at BlockChain.cpp:4353, queue = 'com.apple.main-thread, stop reason = 
EXC_BAD_ACCESS (code=1, address=0x10ba00000)
    frame #0: 0x000000010000dc04 blockchain.out`BlockChainImpl::readBlockHeader(this=0x0000000101000000) + 310 at BlockChain.cpp:4353
   4350                     for (uint32_t i=0; i<c; i++)
   4351                     {
   4352                         const uint32_t *check = (const uint32_t *)&temp[i];
-> 4353                         if ( *check == MAGIC_ID )
   4354                         {
   4355                             printf("Found the next block header after skipping: %s bytes forward in the file.\r\n", formatNumber(i) );
   4356                             lastBlockRead+=i; // advance to this location.

i = 10485757
temp = 0x000000010a000000
check = 0x000000010a9ffffd

The bad access is to 0x10ba00000, three bytes past check
((char*)check)[0] = 0
((char*)check)[1] = 0
((char*)check)[2] = 0
((char*)check)[3] = segfault

What version of the product are you using? On what operating system?

svn revision 55 running on OS X Mavericks

Please provide any additional information below.

I already fixed the file path separator.
The program takes less than a second to get to the point of the crash!

Original issue reported on code.google.com by bruce.ho...@gmail.com on 5 Jan 2014 at 11:13

GoogleCodeExporter commented 9 years ago
The problem is overrunning the end of the allocated space for temp.  The 
following patch fixes it.

Index: BlockChain.cpp
===================================================================
--- BlockChain.cpp  (revision 55)
+++ BlockChain.cpp  (working copy)
@@ -4347,7 +4347,7 @@
                bool found = false;
                if ( c > 0 )
                {
-                   for (uint32_t i=0; i<c; i++)
+                   for (uint32_t i=0; i<=(c-sizeof(uint32_t)); i++)
                    {
                        const uint32_t *check = (const uint32_t *)&temp[i];
                        if ( *check == MAGIC_ID )

Now everything appears to be parsed and the end of the output is

Total Blocks: 278,732
Total Transactions: 30,450,226
Total Inputs: 67,033,514
Total Outputs: 74,892,566

real    2m7.937s
user    1m51.051s
sys 0m7.805s

The number of blocks and transactions is correct (at the moment, obviously).

Original comment by bruce.ho...@gmail.com on 5 Jan 2014 at 11:27