From 536d3362b887074370420e2ffbb63988c96d7a7d Mon Sep 17 00:00:00 2001 From: azuchi Date: Fri, 7 Jun 2019 14:26:15 +0900 Subject: [PATCH] Fix the error by adding skip processing when incomplete data is included in the RAW block file If Core's WriteBlockToDisk ftell fails, only the magic byte and size will be written and the block body will be unwritten data. skip that's data. --- src/bulk.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/bulk.rs b/src/bulk.rs index 3752020..54a45b4 100644 --- a/src/bulk.rs +++ b/src/bulk.rs @@ -138,6 +138,19 @@ fn parse_blocks(blob: Vec, magic: u32) -> Result> { .chain_err(|| format!("seek {} failed", block_size))?; let end = cursor.position() as usize; + // If Core's WriteBlockToDisk ftell fails, only the magic byte and size will be written + // and the block body will be unwritten data. skip that's data. + let mut tmp_cursor = Cursor::new(&blob[start..(start + 4)]); + match u32::consensus_decode(&mut tmp_cursor){ + Ok(value) => { + if magic == value{ + cursor.set_position(start as u64); + continue; + } + } + Err(_) => break, // EOF + } + let block: Block = deserialize(&blob[start..end]) .chain_err(|| format!("failed to parse block at {}..{}", start, end))?; blocks.push(block);