diff --git a/libfsapfs/libfsapfs_compressed_data_handle.c b/libfsapfs/libfsapfs_compressed_data_handle.c index 93486a0..8724e2a 100644 --- a/libfsapfs/libfsapfs_compressed_data_handle.c +++ b/libfsapfs/libfsapfs_compressed_data_handle.c @@ -82,6 +82,7 @@ int libfsapfs_compressed_data_handle_initialize( } if( ( compression_method != LIBFSAPFS_COMPRESSION_METHOD_DEFLATE ) && ( compression_method != LIBFSAPFS_COMPRESSION_METHOD_LZVN ) + && ( compression_method != LIBFSAPFS_COMPRESSION_METHOD_RAW ) && ( compression_method != LIBFSAPFS_COMPRESSION_METHOD_UNKNOWN5 ) ) { libcerror_error_set( @@ -459,7 +460,8 @@ int libfsapfs_compressed_data_handle_get_compressed_block_offsets( compressed_descriptors_offset += 4; compressed_block_descriptor_size = 8; } - else if( data_handle->compression_method == LIBFSAPFS_COMPRESSION_METHOD_LZVN ) + else if( ( data_handle->compression_method == LIBFSAPFS_COMPRESSION_METHOD_LZVN ) + || ( data_handle->compression_method == LIBFSAPFS_COMPRESSION_METHOD_RAW ) ) { segment_data_offset = 0; diff --git a/libfsapfs/libfsapfs_compression.c b/libfsapfs/libfsapfs_compression.c index aac9264..49fe396 100644 --- a/libfsapfs/libfsapfs_compression.c +++ b/libfsapfs/libfsapfs_compression.c @@ -149,7 +149,7 @@ int libfsapfs_decompress_data( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to compressed to uncompressed data.", + "%s: unable to copy compressed to uncompressed data.", function ); return( -1 ); @@ -274,6 +274,71 @@ int libfsapfs_decompress_data( #endif /* ( defined( HAVE_ZLIB ) && defined( HAVE_ZLIB_UNCOMPRESS ) ) || defined( ZLIB_DLL ) */ } } + else if( compression_method == LIBFSAPFS_COMPRESSION_METHOD_RAW ) + { + if( ( compressed_data_size < 1 ) + || ( compressed_data[ 0 ] != 0xcc ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid raw compressed data - unsupported marker byte.", + function ); + + return( -1 ); + } + if( compressed_data_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid compressed data size value exceeds maximum.", + function ); + + return( -1 ); + } + if( *uncompressed_data_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid uncompressed data size value exceeds maximum.", + function ); + + return( -1 ); + } + if( ( compressed_data_size - 1 ) > *uncompressed_data_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: compressed data size value exceeds uncompressed data size.", + function ); + + return( -1 ); + } + *uncompressed_data_size = compressed_data_size - 1; + + if( memory_copy( + uncompressed_data, + &( compressed_data[ 1 ] ), + *uncompressed_data_size ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_COPY_FAILED, + "%s: unable to copy compressed to uncompressed data.", + function ); + + return( -1 ); + } + result = 1; + } #ifdef TODO /* TODO need sample data */ else if( compression_method == LIBFSAPFS_COMPRESSION_METHOD_LZFSE ) @@ -347,7 +412,7 @@ int libfsapfs_decompress_data( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to compressed to uncompressed data.", + "%s: unable to copy compressed to uncompressed data.", function ); return( -1 ); diff --git a/libfsapfs/libfsapfs_definitions.h.in b/libfsapfs/libfsapfs_definitions.h.in index 147715e..cb21b71 100644 --- a/libfsapfs/libfsapfs_definitions.h.in +++ b/libfsapfs/libfsapfs_definitions.h.in @@ -90,6 +90,7 @@ enum LIBFSAPFS_COMPRESSION_METHODS LIBFSAPFS_COMPRESSION_METHOD_DEFLATE = 1, LIBFSAPFS_COMPRESSION_METHOD_LZFSE = 2, LIBFSAPFS_COMPRESSION_METHOD_LZVN = 3, + LIBFSAPFS_COMPRESSION_METHOD_RAW = 4, LIBFSAPFS_COMPRESSION_METHOD_UNKNOWN5 = 5 }; diff --git a/libfsapfs/libfsapfs_file_entry.c b/libfsapfs/libfsapfs_file_entry.c index 657356d..0983a1f 100644 --- a/libfsapfs/libfsapfs_file_entry.c +++ b/libfsapfs/libfsapfs_file_entry.c @@ -4357,6 +4357,11 @@ int libfsapfs_internal_file_entry_get_data_stream( compression_method = LIBFSAPFS_COMPRESSION_METHOD_LZVN; break; + case 9: + case 10: + compression_method = LIBFSAPFS_COMPRESSION_METHOD_RAW; + break; + case 11: case 12: compression_method = LIBFSAPFS_COMPRESSION_METHOD_LZFSE; @@ -4374,7 +4379,8 @@ int libfsapfs_internal_file_entry_get_data_stream( goto on_error; } if( ( internal_file_entry->compressed_data_header->compression_method == 4 ) - || ( internal_file_entry->compressed_data_header->compression_method == 8 ) ) + || ( internal_file_entry->compressed_data_header->compression_method == 8 ) + || ( internal_file_entry->compressed_data_header->compression_method == 10 ) ) { if( libfsapfs_attributes_get_data_stream( internal_file_entry->resource_fork_attribute_values, diff --git a/tests/fsapfs_test_compressed_data_handle.c b/tests/fsapfs_test_compressed_data_handle.c index c9e2338..bd2b653 100644 --- a/tests/fsapfs_test_compressed_data_handle.c +++ b/tests/fsapfs_test_compressed_data_handle.c @@ -21,6 +21,7 @@ #include #include +#include #include #if defined( HAVE_STDLIB_H ) || defined( WINAPI ) @@ -38,11 +39,26 @@ #include "../libfsapfs/libfsapfs_data_stream.h" #include "../libfsapfs/libfsapfs_definitions.h" +/* Single chunk (7) LZVN compresssed data + */ uint8_t fsapfs_test_compressed_data_handle_lzvn_compressed_data1[ 35 ] = { 0x66, 0x70, 0x6d, 0x63, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x06 }; +/* Single chunk raw (9) compresssed data + */ +uint8_t fsapfs_test_compressed_data_handle_raw_chunk_compressed_data1[ 33 ] = { + 0x66, 0x70, 0x6d, 0x63, 0x09, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f }; + +/* Multi chunk raw (10) compresssed data + */ +uint8_t fsapfs_test_compressed_data_handle_raw_compressed_data1[ 25 ] = { + 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + #if defined( __GNUC__ ) && !defined( LIBFSAPFS_DLL_IMPORT ) /* Tests the libfsapfs_compressed_data_handle_initialize function @@ -463,24 +479,98 @@ int fsapfs_test_compressed_data_handle_get_compressed_block_offsets( "error", error ); - /* Test error cases + /* Clean up */ - result = libfsapfs_compressed_data_handle_get_compressed_block_offsets( - NULL, - NULL, + result = libfsapfs_compressed_data_handle_free( + &compressed_data_handle, &error ); FSAPFS_TEST_ASSERT_EQUAL_INT( "result", result, - -1 ); + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfdata_stream_free( + &compressed_data_stream, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Initialize test + */ + result = libfsapfs_data_stream_initialize_from_data( + &compressed_data_stream, + fsapfs_test_compressed_data_handle_raw_chunk_compressed_data1, + 33, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( "error", error ); - libcerror_error_free( - &error ); + result = libfsapfs_compressed_data_handle_initialize( + &compressed_data_handle, + compressed_data_stream, + 16, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + result = libfsapfs_compressed_data_handle_get_compressed_block_offsets( + compressed_data_handle, + NULL, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); /* Clean up */ @@ -518,42 +608,98 @@ int fsapfs_test_compressed_data_handle_get_compressed_block_offsets( "error", error ); - return( 1 ); + /* Initialize test + */ + result = libfsapfs_data_stream_initialize_from_data( + &compressed_data_stream, + fsapfs_test_compressed_data_handle_raw_compressed_data1, + 25, + &error ); -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( compressed_data_handle != NULL ) - { - libfsapfs_compressed_data_handle_free( - &compressed_data_handle, - NULL ); - } - if( compressed_data_stream != NULL ) - { - libfdata_stream_free( - &compressed_data_stream, - NULL ); - } - return( 0 ); -} + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); -/* Tests the libfsapfs_compressed_data_handle_read_segment_data function - * Returns 1 if successful or 0 if not - */ -int fsapfs_test_compressed_data_handle_read_segment_data( - void ) -{ - uint8_t segment_data[ 32 ]; + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_stream", + compressed_data_stream ); - libcerror_error_t *error = NULL; - libfdata_stream_t *compressed_data_stream = NULL; - libfsapfs_compressed_data_handle_t *compressed_data_handle = NULL; - ssize_t read_count = 0; - int result = 0; + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfsapfs_compressed_data_handle_initialize( + &compressed_data_handle, + compressed_data_stream, + 16, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + result = libfsapfs_compressed_data_handle_get_compressed_block_offsets( + compressed_data_handle, + NULL, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Clean up + */ + result = libfsapfs_compressed_data_handle_free( + &compressed_data_handle, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfdata_stream_free( + &compressed_data_stream, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); /* Initialize test */ @@ -596,8 +742,460 @@ int fsapfs_test_compressed_data_handle_read_segment_data( "error", error ); - /* Test regular cases + /* Test error cases + */ + result = libfsapfs_compressed_data_handle_get_compressed_block_offsets( + NULL, + NULL, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + /* Clean up */ + result = libfsapfs_compressed_data_handle_free( + &compressed_data_handle, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfdata_stream_free( + &compressed_data_stream, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( compressed_data_handle != NULL ) + { + libfsapfs_compressed_data_handle_free( + &compressed_data_handle, + NULL ); + } + if( compressed_data_stream != NULL ) + { + libfdata_stream_free( + &compressed_data_stream, + NULL ); + } + return( 0 ); +} + +/* Tests the libfsapfs_compressed_data_handle_read_segment_data function + * Returns 1 if successful or 0 if not + */ +int fsapfs_test_compressed_data_handle_read_segment_data( + void ) +{ + uint8_t expected_segment_data2[ 16 ] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + + uint8_t segment_data[ 32 ]; + + libcerror_error_t *error = NULL; + libfdata_stream_t *compressed_data_stream = NULL; + libfsapfs_compressed_data_handle_t *compressed_data_handle = NULL; + ssize_t read_count = 0; + int result = 0; + + /* Initialize test + */ + result = libfsapfs_data_stream_initialize_from_data( + &compressed_data_stream, + fsapfs_test_compressed_data_handle_lzvn_compressed_data1, + 35, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfsapfs_compressed_data_handle_initialize( + &compressed_data_handle, + compressed_data_stream, + 16, + LIBFSAPFS_COMPRESSION_METHOD_LZVN, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + read_count = libfsapfs_compressed_data_handle_read_segment_data( + compressed_data_handle, + NULL, + 0, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_SSIZE( + "read_count", + read_count, + (ssize_t) 16 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* TODO compare segment_data with expected_segment_data1 */ + + /* Clean up + */ + result = libfsapfs_compressed_data_handle_free( + &compressed_data_handle, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfdata_stream_free( + &compressed_data_stream, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Initialize test + */ + result = libfsapfs_data_stream_initialize_from_data( + &compressed_data_stream, + fsapfs_test_compressed_data_handle_raw_chunk_compressed_data1, + 33, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfsapfs_compressed_data_handle_initialize( + &compressed_data_handle, + compressed_data_stream, + 16, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + read_count = libfsapfs_compressed_data_handle_read_segment_data( + compressed_data_handle, + NULL, + 0, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_SSIZE( + "read_count", + read_count, + (ssize_t) 16 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = memory_compare( + segment_data, + expected_segment_data2, + 16 ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + + /* Clean up + */ + result = libfsapfs_compressed_data_handle_free( + &compressed_data_handle, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfdata_stream_free( + &compressed_data_stream, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Initialize test + */ + result = libfsapfs_data_stream_initialize_from_data( + &compressed_data_stream, + fsapfs_test_compressed_data_handle_raw_compressed_data1, + 25, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfsapfs_compressed_data_handle_initialize( + &compressed_data_handle, + compressed_data_stream, + 16, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test regular cases + */ + read_count = libfsapfs_compressed_data_handle_read_segment_data( + compressed_data_handle, + NULL, + 0, + 0, + segment_data, + 16, + 0, + 0, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_SSIZE( + "read_count", + read_count, + (ssize_t) 16 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = memory_compare( + segment_data, + expected_segment_data2, + 16 ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + + /* Clean up + */ + result = libfsapfs_compressed_data_handle_free( + &compressed_data_handle, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfdata_stream_free( + &compressed_data_stream, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Initialize test + */ + result = libfsapfs_data_stream_initialize_from_data( + &compressed_data_stream, + fsapfs_test_compressed_data_handle_lzvn_compressed_data1, + 35, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_stream", + compressed_data_stream ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfsapfs_compressed_data_handle_initialize( + &compressed_data_handle, + compressed_data_stream, + 16, + LIBFSAPFS_COMPRESSION_METHOD_LZVN, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "compressed_data_handle", + compressed_data_handle ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); /* Test error cases */ diff --git a/tests/fsapfs_test_compression.c b/tests/fsapfs_test_compression.c index c267201..561ce2a 100644 --- a/tests/fsapfs_test_compression.c +++ b/tests/fsapfs_test_compression.c @@ -56,6 +56,10 @@ uint8_t fsapfs_test_compression_lzvn_uncompressed_data1[ 17 ] = { uint8_t fsapfs_test_compression_uncompressed_data1[ 16 ] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; +uint8_t fsapfs_test_compression_raw_data1[ 17 ] = { + 0xcc, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f }; + #if defined( __GNUC__ ) && !defined( LIBFSAPFS_DLL_IMPORT ) /* Tests the libfsapfs_decompress_data function @@ -208,6 +212,40 @@ int fsapfs_test_decompress_data( result, 0 ); + uncompressed_data_size = 16; + + result = libfsapfs_decompress_data( + fsapfs_test_compression_raw_data1, + 17, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + uncompressed_data, + &uncompressed_data_size, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FSAPFS_TEST_ASSERT_EQUAL_SIZE( + "uncompressed_data_size", + uncompressed_data_size, + (size_t) 16 ); + + FSAPFS_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = memory_compare( + uncompressed_data, + fsapfs_test_compression_uncompressed_data1, + 16 ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + /* Test error cases */ uncompressed_data_size = 16; @@ -379,6 +417,34 @@ int fsapfs_test_decompress_data( libcerror_error_free( &error ); + /* Test with unsupported raw compressed data + */ + uncompressed_data_size = 16; + + fsapfs_test_compression_raw_data1[ 0 ] = 0x00; + + result = libfsapfs_decompress_data( + fsapfs_test_compression_raw_data1, + 17, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + uncompressed_data, + &uncompressed_data_size, + &error ); + + fsapfs_test_compression_raw_data1[ 0 ] = 0xcc; + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + #if defined( HAVE_FSAPFS_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) uncompressed_data_size = 16; @@ -481,6 +547,72 @@ int fsapfs_test_decompress_data( libcerror_error_free( &error ); + uncompressed_data_size = 16; + + result = libfsapfs_decompress_data( + fsapfs_test_compression_raw_data1, + (size_t) SSIZE_MAX + 1, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + uncompressed_data, + &uncompressed_data_size, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + uncompressed_data_size = 0; + + result = libfsapfs_decompress_data( + fsapfs_test_compression_raw_data1, + 17, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + uncompressed_data, + &uncompressed_data_size, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + uncompressed_data_size = (size_t) SSIZE_MAX + 1; + + result = libfsapfs_decompress_data( + fsapfs_test_compression_raw_data1, + 17, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + uncompressed_data, + &uncompressed_data_size, + &error ); + + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + #if defined( HAVE_FSAPFS_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) uncompressed_data_size = 16; @@ -517,6 +649,42 @@ int fsapfs_test_decompress_data( } #endif /* defined( HAVE_FSAPFS_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) */ +#if defined( HAVE_FSAPFS_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) + + uncompressed_data_size = 16; + + /* Test libfsapfs_decompress_data with memcpy failing + */ + fsapfs_test_memcpy_attempts_before_fail = 0; + + result = libfsapfs_decompress_data( + fsapfs_test_compression_raw_data1, + 17, + LIBFSAPFS_COMPRESSION_METHOD_RAW, + uncompressed_data, + &uncompressed_data_size, + &error ); + + if( fsapfs_test_memcpy_attempts_before_fail != -1 ) + { + fsapfs_test_memcpy_attempts_before_fail = -1; + } + else + { + FSAPFS_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FSAPFS_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } +#endif /* defined( HAVE_FSAPFS_TEST_MEMORY ) && defined( OPTIMIZATION_DISABLED ) */ + return( 1 ); on_error: