icoutils/0020-wrestool-Use-size_t-for-resource-size.patch
Richard W.M. Jones 86a1ed311e Add a series of upstream patches to enable compiler warnings and
fix multiple issues.

Revert one of the checks which breaks processing of PE binaries.

Removed the 'Group' line, not needed with modern Fedora/RPM.
2017-03-10 12:18:04 +00:00

151 lines
5.6 KiB
Diff

From cc0b474840c76dab5091d0a0f0d16e330aff4e6b Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 9 Mar 2017 14:43:37 +0000
Subject: [PATCH 20/26] wrestool: Use size_t for resource size.
The resource size returned by get_resource_entry comes from
Win32ImageResourceDataEntry.size which has type uint32_t. Even on 32
bit machines, int is not large enough to store this size without
overflowing.
We could use uint32_t here to match what the Windows file gives us.
However since this represents the size of a C object in our memory
space, it's safer still to use size_t because that can never overflow
(notice that along some paths we add to the size).
---
wrestool/extract.c | 19 ++++++++++---------
wrestool/restable.c | 7 ++++---
wrestool/wrestool.h | 4 ++--
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/wrestool/extract.c b/wrestool/extract.c
index a0c516c..e1140a3 100644
--- a/wrestool/extract.c
+++ b/wrestool/extract.c
@@ -28,15 +28,15 @@
#include "fileread.h"
#include "wrestool.h"
-static void *extract_group_icon_cursor_resource(WinLibrary *, WinResource *, char *, int *, bool);
-static void *extract_bitmap_resource(WinLibrary *, WinResource *, int *);
+static void *extract_group_icon_cursor_resource(WinLibrary *, WinResource *, char *, size_t *, bool);
+static void *extract_bitmap_resource(WinLibrary *, WinResource *, size_t *);
void
extract_resources_callback (WinLibrary *fi, WinResource *wr,
WinResource *type_wr, WinResource *name_wr,
WinResource *lang_wr)
{
- int size;
+ size_t size;
bool free_it;
void *memory;
char *outname;
@@ -75,7 +75,7 @@ extract_resources_callback (WinLibrary *fi, WinResource *wr,
* Extract a resource, returning pointer to data.
*/
void *
-extract_resource (WinLibrary *fi, WinResource *wr, int *size,
+extract_resource (WinLibrary *fi, WinResource *wr, size_t *size,
bool *free_it, char *type, char *lang, bool raw)
{
char *str;
@@ -123,12 +123,13 @@ extract_resource (WinLibrary *fi, WinResource *wr, int *size,
*/
static void *
extract_group_icon_cursor_resource(WinLibrary *fi, WinResource *wr, char *lang,
- int *ressize, bool is_icon)
+ size_t *ressize, bool is_icon)
{
Win32CursorIconDir *icondir;
Win32CursorIconFileDir *fileicondir;
char *memory;
- int c, size, offset, skipped;
+ int c, offset, skipped;
+ size_t size;
/* get resource data and size */
icondir = (Win32CursorIconDir *) get_resource_entry(fi, wr, &size);
@@ -142,7 +143,7 @@ extract_group_icon_cursor_resource(WinLibrary *fi, WinResource *wr, char *lang,
skipped = 0;
for (c = 0 ; c < icondir->count ; c++) {
int level;
- int iconsize;
+ size_t iconsize;
char name[14];
WinResource *fwr;
@@ -265,13 +266,13 @@ extract_group_icon_cursor_resource(WinLibrary *fi, WinResource *wr, char *lang,
* the returned memory block will be placed.
*/
static void *
-extract_bitmap_resource(WinLibrary *fi, WinResource *wr, int *ressize)
+extract_bitmap_resource(WinLibrary *fi, WinResource *wr, size_t *ressize)
{
Win32BitmapInfoHeader info;
uint8_t *result;
uint8_t *resentry;
uint32_t offbits;
- int size;
+ size_t size;
resentry=(uint8_t *)(get_resource_entry(fi,wr,&size));
diff --git a/wrestool/restable.c b/wrestool/restable.c
index fa781f0..1547979 100644
--- a/wrestool/restable.c
+++ b/wrestool/restable.c
@@ -117,7 +117,8 @@ print_resources_callback (WinLibrary *fi, WinResource *wr,
WinResource *lang_wr)
{
char *type, *offset;
- int32_t id, size;
+ int32_t id;
+ size_t size;
/* get named resource type if possible */
type = NULL;
@@ -129,7 +130,7 @@ print_resources_callback (WinLibrary *fi, WinResource *wr,
if (offset == NULL)
return;
- printf(_("--type=%s --name=%s%s%s [%s%s%soffset=0x%x size=%d]\n"),
+ printf(_("--type=%s --name=%s%s%s [%s%s%soffset=0x%x size=%zu]\n"),
get_resource_id_quoted(type_wr),
get_resource_id_quoted(name_wr),
(lang_wr->id[0] != '\0' ? _(" --language=") : ""),
@@ -203,7 +204,7 @@ decode_pe_resource_id (WinLibrary *fi, WinResource *wr, uint32_t value)
}
void *
-get_resource_entry (WinLibrary *fi, WinResource *wr, int *size)
+get_resource_entry (WinLibrary *fi, WinResource *wr, size_t *size)
{
if (fi->is_PE_binary) {
Win32ImageResourceDataEntry *dataent;
diff --git a/wrestool/wrestool.h b/wrestool/wrestool.h
index 635a0ef..e4bae73 100644
--- a/wrestool/wrestool.h
+++ b/wrestool/wrestool.h
@@ -92,7 +92,7 @@ typedef void (*DoResourceCallback) (WinLibrary *, WinResource *, WinResource *,
/* WinResource *list_resources (WinLibrary *, WinResource *, int *); */
bool read_library (WinLibrary *);
WinResource *find_resource (WinLibrary *, const char *, const char *, const char *, int *);
-void *get_resource_entry (WinLibrary *, WinResource *, int *);
+void *get_resource_entry (WinLibrary *, WinResource *, size_t *);
void do_resources (WinLibrary *, char *, char *, char *, DoResourceCallback);
void print_resources_callback (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *);
/* bool compare_resource_id (WinResource *, char *); */
@@ -102,7 +102,7 @@ char *res_type_id_to_string (int);
char *get_destination_name (WinLibrary *, char *, char *, char *);
/* extract.c */
-void *extract_resource (WinLibrary *, WinResource *, int *, bool *, char *, char *, bool);
+void *extract_resource (WinLibrary *, WinResource *, size_t *, bool *, char *, char *, bool);
void extract_resources_callback (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *);
#endif
--
2.10.2