From 6c03975e32861b0188f7a6cbd3f14f5b57e46319 Mon Sep 17 00:00:00 2001 From: Andy Ragusa Date: Thu, 8 Aug 2024 07:38:49 -0700 Subject: [PATCH] Some cleanup --- libclamav/ole2_extract_images.h | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/libclamav/ole2_extract_images.h b/libclamav/ole2_extract_images.h index 9d7242dff9..f4ebafb6cf 100644 --- a/libclamav/ole2_extract_images.h +++ b/libclamav/ole2_extract_images.h @@ -397,7 +397,7 @@ typedef struct { } ole2_image_directory_t; /* - * This structure is used to keep track of a poiner's offset, to determine if it will cross + * This structure is used to keep track of a pointer's offset, to determine if it will cross * a block that is used by the DIFAT * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/05060311-bfce-4b12-874d-71fd4ce63aea * The strategy is to keep updating ptr to point to the data structure that is currently being read, @@ -427,6 +427,10 @@ typedef struct __attribute__((packed)) { } ole2_pointer_t; +static void update_pointer(ole2_pointer_t * ptr, size_t offset) { + ptr->ptr = &(ptr->ptr[offset]); +} + /* https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-odraw/5dc1b9ed-818c-436f-8a4f-905a7ebb1ba9 */ typedef struct __attribute__((packed)) { uint16_t recVer_recInstance; @@ -690,7 +694,11 @@ static void saveImageFile( cli_ctx * ctx, ole2_header_t * ole2Hdr, ole2_pointer_ /*Get more space from the fmap to account for the extra block*/ const uint8_t * ptr = fmap_need_off_once(ole2Hdr->map, ole2Ptr->stream_file_offset, (ole2Ptr->ptr - ole2Ptr->base_ptr) + increment + size); if (ptr != ole2Ptr->base_ptr) { +#if 0 ole2Ptr->ptr = &(ptr[ole2Ptr->ptr - ole2Ptr->base_ptr]); +#else + update_pointer(ole2Ptr, ole2Ptr->ptr - ole2Ptr->base_ptr); +#endif ole2Ptr->base_ptr = ptr; } } @@ -729,7 +737,11 @@ static void saveImageFile( cli_ctx * ctx, ole2_header_t * ole2Hdr, ole2_pointer_ } done: +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[size + totalIncrement]); +#else + update_pointer(ole2Ptr, size + totalIncrement); +#endif if (tempfile && !ctx->engine->keeptmp) { remove(tempfile); @@ -762,7 +774,11 @@ static void processOfficeArtBlipGeneric(cli_ctx * ctx, ole2_header_t * ole2Hdr, } offset += bytesAfterUIDs; /*metafile header*/ +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[offset]); +#else + update_pointer(ole2Ptr, offset); +#endif saveImageFile(ctx, ole2Hdr, ole2Ptr, rh->recLen - offset); } @@ -794,7 +810,11 @@ static void processOfficeArtBlipJPEG(cli_ctx * ctx, ole2_header_t * ole2Hdr, Off } offset += 1; /*metafile header*/ +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[offset]); +#else + update_pointer(ole2Ptr, offset); +#endif saveImageFile(ctx, ole2Hdr, ole2Ptr, rh->recLen - offset); } @@ -834,7 +854,11 @@ static size_t processOfficeArtBlip(cli_ctx * ctx, ole2_header_t * ole2Hdr, ole2_ #define RECTYPE_OFFICE_ART_BLIP_TIFF 0xf029 #define RECTYPE_OFFICE_ART_BLIP_JPEG2 0xf02a +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[offset]); +#else + update_pointer(ole2Ptr, offset); +#endif switch (rh.recType) { case RECTYPE_OFFICE_ART_BLIP_EMF: processOfficeArtBlipEMF(ctx, ole2Hdr, &rh, ole2Ptr); @@ -865,7 +889,11 @@ static size_t processOfficeArtBlip(cli_ctx * ctx, ole2_header_t * ole2Hdr, ole2_ } done: +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[sizeof(rh) + rh.recLen]); +#else + update_pointer(ole2Ptr, sizeof(rh) + rh.recLen); +#endif return (sizeof(rh) + rh.recLen); } @@ -892,11 +920,19 @@ static size_t processOfficeArtFBSE(cli_ctx * ctx, ole2_header_t *hdr, OfficeArtR offset += fbse.cbName; +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[offset]); +#else + update_pointer(ole2Ptr, offset); +#endif if (imageHeader->recLen == (sizeof(OfficeArtFBSEKnown) + fbse.cbName + fbse.size)) { /* The BLIP is embedded in this record*/ processOfficeArtBlip(ctx, hdr, ole2Ptr); +#if 0 ole2Ptr->ptr = &(ole2Ptr->ptr[fbse.size]); +#else + update_pointer(ole2Ptr, fbse.size); +#endif offset += fbse.size; } else { /* The BLIP is in the 'WordDocument' stream. */