diff --git a/tsk/fs/ntfs.c b/tsk/fs/ntfs.c index 132c314a56c594426d053d491b9d3f9603899d4d..f6ae77de478d60a618fcc94bb3b6108551af900d 100755 --- a/tsk/fs/ntfs.c +++ b/tsk/fs/ntfs.c @@ -867,7 +867,6 @@ static uint8_t ntfs_uncompress_compunit(NTFS_COMP_INFO * comp) { size_t cl_index; - uint8_t recover_data = 0; // set to 1 when we proceed even with potentially corrupt data tsk_error_reset(); @@ -894,13 +893,11 @@ ntfs_uncompress_compunit(NTFS_COMP_INFO * comp) blk_end = cl_index + blk_size; if (blk_end > comp->comp_len) { - blk_end = comp->comp_len - 1; - if (tsk_verbose) - tsk_fprintf(stderr, - "WARNING: ntfs_uncompress_compunit: Block length longer than buffer length. Attempting to continue.\n"); - recover_data = 1; - // return 0; // zero out the entire block - // if we don't return 0, let the function continue to display as much decompressed data as possible + tsk_error_set_errno(TSK_ERR_FS_FWALK); + tsk_error_set_errstr + ("ntfs_uncompress_compunit: Block length longer than buffer length: %" + PRIuSIZE "", blk_end); + return 1; } if (tsk_verbose) @@ -1084,10 +1081,7 @@ ntfs_uncompress_compunit(NTFS_COMP_INFO * comp) } } } // end of loop inside of compression unit - // if we are attempting to recover, we may not have decompressed an entire CU. Set uncomp_idx to the expected size. - if (recover_data) { - comp->uncomp_idx = comp->buf_size_b; - } + return 0; } @@ -1249,7 +1243,6 @@ ntfs_attr_walk_special(const TSK_FS_ATTR * fs_attr, TSK_OFF_T off = 0; int retval; uint8_t stop_loop = 0; - uint8_t init_size_reached = 0; if (fs_attr->nrd.compsize <= 0) { tsk_error_set_errno(TSK_ERR_FS_FWALK); @@ -1365,29 +1358,18 @@ ntfs_attr_walk_special(const TSK_FS_ATTR * fs_attr, size_t i; // decompress the unit - uint8_t reset_uncompress_for_init_size = 0; - if (!init_size_reached) { - if (ntfs_proc_compunit(ntfs, &comp, comp_unit, + if (ntfs_proc_compunit(ntfs, &comp, comp_unit, comp_unit_idx)) { - tsk_error_set_errstr2("%" PRIuINUM " - type: %" - PRIu32 " id: %d Status: %s", - fs_attr->fs_file->meta->addr, fs_attr->type, - fs_attr->id, - (fs_attr->fs_file->meta-> - flags & TSK_FS_META_FLAG_ALLOC) ? - "Allocated" : "Deleted"); - free(comp_unit); - ntfs_uncompress_done(&comp); - return 1; - } - - // handle the initialized size - int64_t remanining_init_size = fs_attr->nrd.initsize - off; - if (remanining_init_size < comp.buf_size_b) { - memset(comp.uncomp_buf + remanining_init_size, 0, comp.buf_size_b - remanining_init_size); - init_size_reached = 1; - reset_uncompress_for_init_size = 1; - } + tsk_error_set_errstr2("%" PRIuINUM " - type: %" + PRIu32 " id: %d Status: %s", + fs_attr->fs_file->meta->addr, fs_attr->type, + fs_attr->id, + (fs_attr->fs_file->meta-> + flags & TSK_FS_META_FLAG_ALLOC) ? + "Allocated" : "Deleted"); + free(comp_unit); + ntfs_uncompress_done(&comp); + return 1; } // now call the callback with the uncompressed data @@ -1455,11 +1437,6 @@ ntfs_attr_walk_special(const TSK_FS_ATTR * fs_attr, } } comp_unit_idx = 0; - - if (reset_uncompress_for_init_size) { // clear out stale data in the buffers for further callbacks and set up for reading 0's - ntfs_uncompress_reset(&comp); - comp.uncomp_idx = comp.buf_size_b; - } } if (stop_loop) @@ -1527,7 +1504,6 @@ ntfs_file_read_special(const TSK_FS_ATTR * a_fs_attr, uint32_t comp_unit_idx = 0; NTFS_COMP_INFO comp; size_t buf_idx = 0; - uint8_t init_size_reached = 0; if (a_fs_attr->nrd.compsize <= 0) { tsk_error_set_errno(TSK_ERR_FS_FWALK); @@ -1622,28 +1598,18 @@ ntfs_file_read_special(const TSK_FS_ATTR * a_fs_attr, size_t cpylen; // decompress the unit - uint8_t reset_uncompress_for_init_size = 0; - if (!init_size_reached) { - if (ntfs_proc_compunit(ntfs, &comp, comp_unit, + if (ntfs_proc_compunit(ntfs, &comp, comp_unit, comp_unit_idx)) { - tsk_error_set_errstr2("%" PRIuINUM " - type: %" - PRIu32 " id: %d Status: %s", - a_fs_attr->fs_file->meta->addr, - a_fs_attr->type, a_fs_attr->id, - (a_fs_attr->fs_file->meta-> - flags & TSK_FS_META_FLAG_ALLOC) ? - "Allocated" : "Deleted"); - free(comp_unit); - ntfs_uncompress_done(&comp); - return -1; - } - // handle the initialized size - int64_t remanining_init_size = a_fs_attr->nrd.initsize - buf_idx - a_offset; - if (remanining_init_size < comp.buf_size_b) { - memset(comp.uncomp_buf + remanining_init_size, 0, comp.buf_size_b - remanining_init_size); - init_size_reached = 1; - reset_uncompress_for_init_size = 1; - } + tsk_error_set_errstr2("%" PRIuINUM " - type: %" + PRIu32 " id: %d Status: %s", + a_fs_attr->fs_file->meta->addr, + a_fs_attr->type, a_fs_attr->id, + (a_fs_attr->fs_file->meta-> + flags & TSK_FS_META_FLAG_ALLOC) ? + "Allocated" : "Deleted"); + free(comp_unit); + ntfs_uncompress_done(&comp); + return -1; } // copy uncompressed data to the output buffer @@ -1674,11 +1640,6 @@ ntfs_file_read_special(const TSK_FS_ATTR * a_fs_attr, byteoffset = 0; buf_idx += cpylen; comp_unit_idx = 0; - - if (reset_uncompress_for_init_size) { // clear out stale data in the buffers for further callbacks and set up for reading 0's - ntfs_uncompress_reset(&comp); - comp.uncomp_idx = comp.buf_size_b; - } } /* If it is a sparse run, don't increment the addr so that * it remains 0 */