Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Aug 8, 2024
1 parent 2bd003b commit 6c03975
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion libclamav/ole2_extract_images.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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. */
Expand Down

0 comments on commit 6c03975

Please sign in to comment.