[Bf-blender-cvs] [2d60845786a] master: Cleanup: pass header size to 'is_a' callbacks
Campbell Barton
noreply at git.blender.org
Wed Nov 11 06:14:57 CET 2020
Commit: 2d60845786aeab099c61ffa42b7f72cccc68bff1
Author: Campbell Barton
Date: Wed Nov 11 16:14:06 2020 +1100
Branches: master
https://developer.blender.org/rB2d60845786aeab099c61ffa42b7f72cccc68bff1
Cleanup: pass header size to 'is_a' callbacks
No functional changes, prepare for fixing out-of-bounds access
when reading headers.
===================================================================
M source/blender/imbuf/intern/IMB_filetype.h
M source/blender/imbuf/intern/bmp.c
M source/blender/imbuf/intern/cineon/cineon_dpx.c
M source/blender/imbuf/intern/dds/dds_api.cpp
M source/blender/imbuf/intern/dds/dds_api.h
M source/blender/imbuf/intern/iris.c
M source/blender/imbuf/intern/jp2.c
M source/blender/imbuf/intern/jpeg.c
M source/blender/imbuf/intern/oiio/openimageio_api.cpp
M source/blender/imbuf/intern/oiio/openimageio_api.h
M source/blender/imbuf/intern/openexr/openexr_api.cpp
M source/blender/imbuf/intern/openexr/openexr_api.h
M source/blender/imbuf/intern/png.c
M source/blender/imbuf/intern/radiance_hdr.c
M source/blender/imbuf/intern/targa.c
M source/blender/imbuf/intern/tiff.c
M source/blender/imbuf/intern/util.c
===================================================================
diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h
index 520e810fe32..7bdbbb03227 100644
--- a/source/blender/imbuf/intern/IMB_filetype.h
+++ b/source/blender/imbuf/intern/IMB_filetype.h
@@ -32,7 +32,7 @@ typedef struct ImFileType {
void (*init)(void);
void (*exit)(void);
- int (*is_a)(const unsigned char *buf);
+ bool (*is_a)(const unsigned char *buf, const size_t size);
int (*ftype)(const struct ImFileType *type, const struct ImBuf *ibuf);
struct ImBuf *(*load)(const unsigned char *mem,
size_t size,
@@ -67,7 +67,7 @@ void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty);
/* Type Specific Functions */
/* png */
-int imb_is_a_png(const unsigned char *mem);
+bool imb_is_a_png(const unsigned char *mem, const size_t size);
struct ImBuf *imb_loadpng(const unsigned char *mem,
size_t size,
int flags,
@@ -75,7 +75,7 @@ struct ImBuf *imb_loadpng(const unsigned char *mem,
bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags);
/* targa */
-int imb_is_a_targa(const unsigned char *buf);
+bool imb_is_a_targa(const unsigned char *buf, const size_t size);
struct ImBuf *imb_loadtarga(const unsigned char *mem,
size_t size,
int flags,
@@ -83,7 +83,7 @@ struct ImBuf *imb_loadtarga(const unsigned char *mem,
bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags);
/* iris */
-int imb_is_a_iris(const unsigned char *mem);
+bool imb_is_a_iris(const unsigned char *mem, const size_t size);
struct ImBuf *imb_loadiris(const unsigned char *mem,
size_t size,
int flags,
@@ -91,7 +91,7 @@ struct ImBuf *imb_loadiris(const unsigned char *mem,
bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags);
/* jp2 */
-int imb_is_a_jp2(const unsigned char *buf);
+bool imb_is_a_jp2(const unsigned char *buf, const size_t size);
struct ImBuf *imb_load_jp2(const unsigned char *mem,
size_t size,
int flags,
@@ -102,7 +102,7 @@ struct ImBuf *imb_load_jp2_filepath(const char *filepath,
bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags);
/* jpeg */
-int imb_is_a_jpeg(const unsigned char *mem);
+bool imb_is_a_jpeg(const unsigned char *mem, const size_t size);
bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags);
struct ImBuf *imb_load_jpeg(const unsigned char *buffer,
size_t size,
@@ -110,7 +110,7 @@ struct ImBuf *imb_load_jpeg(const unsigned char *buffer,
char colorspace[IM_MAX_SPACE]);
/* bmp */
-int imb_is_a_bmp(const unsigned char *buf);
+bool imb_is_a_bmp(const unsigned char *buf, const size_t size);
struct ImBuf *imb_bmp_decode(const unsigned char *mem,
size_t size,
int flags,
@@ -118,7 +118,7 @@ struct ImBuf *imb_bmp_decode(const unsigned char *mem,
bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags);
/* cineon */
-int imb_is_a_cineon(const unsigned char *buf);
+bool imb_is_a_cineon(const unsigned char *buf, const size_t size);
bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags);
struct ImBuf *imb_load_cineon(const unsigned char *mem,
size_t size,
@@ -126,7 +126,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem,
char colorspace[IM_MAX_SPACE]);
/* dpx */
-int imb_is_a_dpx(const unsigned char *buf);
+bool imb_is_a_dpx(const unsigned char *buf, const size_t size);
bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags);
struct ImBuf *imb_load_dpx(const unsigned char *mem,
size_t size,
@@ -134,7 +134,7 @@ struct ImBuf *imb_load_dpx(const unsigned char *mem,
char colorspace[IM_MAX_SPACE]);
/* hdr */
-int imb_is_a_hdr(const unsigned char *buf);
+bool imb_is_a_hdr(const unsigned char *buf, const size_t size);
struct ImBuf *imb_loadhdr(const unsigned char *mem,
size_t size,
int flags,
@@ -143,7 +143,7 @@ bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags);
/* tiff */
void imb_inittiff(void);
-int imb_is_a_tiff(const unsigned char *buf);
+bool imb_is_a_tiff(const unsigned char *buf, const size_t size);
struct ImBuf *imb_loadtiff(const unsigned char *mem,
size_t size,
int flags,
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c
index 6d1726af608..9358b67b3ed 100644
--- a/source/blender/imbuf/intern/bmp.c
+++ b/source/blender/imbuf/intern/bmp.c
@@ -72,13 +72,13 @@ typedef struct BMPHEADER {
CHECK_HEADER_FIELD(_mem, "CI") || CHECK_HEADER_FIELD(_mem, "CP") || \
CHECK_HEADER_FIELD(_mem, "IC") || CHECK_HEADER_FIELD(_mem, "PT"))
-static int checkbmp(const uchar *mem)
+static bool checkbmp(const uchar *mem)
{
if (!CHECK_HEADER_FIELD_BMP(mem)) {
return 0;
}
- int ret_val = 0;
+ bool ok = false;
BMPINFOHEADER bmi;
uint u;
@@ -94,15 +94,15 @@ static int checkbmp(const uchar *mem)
if (bmi.biCompression == 0) {
u = LITTLE_SHORT(bmi.biBitCount);
if (u > 0 && u <= 32) {
- ret_val = 1;
+ ok = true;
}
}
}
- return ret_val;
+ return ok;
}
-int imb_is_a_bmp(const uchar *buf)
+bool imb_is_a_bmp(const uchar *buf, size_t UNUSED(size))
{
return checkbmp(buf);
}
diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c
index 7907d648abe..8bbd9fbb285 100644
--- a/source/blender/imbuf/intern/cineon/cineon_dpx.c
+++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c
@@ -188,7 +188,7 @@ bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags)
return imb_save_dpx_cineon(buf, filepath, 1, flags);
}
-int imb_is_a_cineon(const unsigned char *buf)
+bool imb_is_a_cineon(const unsigned char *buf, size_t UNUSED(size))
{
return logImageIsCineon(buf);
}
@@ -198,7 +198,7 @@ ImBuf *imb_load_cineon(const unsigned char *mem,
int flags,
char colorspace[IM_MAX_SPACE])
{
- if (imb_is_a_cineon(mem)) {
+ if (imb_is_a_cineon(mem, size)) {
return imb_load_dpx_cineon(mem, size, 1, flags, colorspace);
}
return NULL;
@@ -209,7 +209,7 @@ bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags)
return imb_save_dpx_cineon(buf, filepath, 0, flags);
}
-int imb_is_a_dpx(const unsigned char *buf)
+bool imb_is_a_dpx(const unsigned char *buf, size_t UNUSED(size))
{
return logImageIsDpx(buf);
}
@@ -219,7 +219,7 @@ ImBuf *imb_load_dpx(const unsigned char *mem,
int flags,
char colorspace[IM_MAX_SPACE])
{
- if (imb_is_a_dpx(mem)) {
+ if (imb_is_a_dpx(mem, size)) {
return imb_load_dpx_cineon(mem, size, 0, flags, colorspace);
}
return NULL;
diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp
index d8bcca7e1f5..78ce8b5ee9b 100644
--- a/source/blender/imbuf/intern/dds/dds_api.cpp
+++ b/source/blender/imbuf/intern/dds/dds_api.cpp
@@ -72,18 +72,19 @@ bool imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/)
return true;
}
-int imb_is_a_dds(const unsigned char *mem) /* note: use at most first 32 bytes */
+/* note: use at most first 32 bytes */
+bool imb_is_a_dds(const unsigned char *mem, size_t UNUSED(size))
{
/* heuristic check to see if mem contains a DDS file */
/* header.fourcc == FOURCC_DDS */
if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' ')) {
- return 0;
+ return false;
}
/* header.size == 124 */
if ((mem[4] != 124) || mem[5] || mem[6] || mem[7]) {
- return 0;
+ return false;
}
- return 1;
+ return true;
}
struct ImBuf *imb_load_dds(const unsigned char *mem,
@@ -108,7 +109,7 @@ struct ImBuf *imb_load_dds(const unsigned char *mem,
*/
colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
- if (!imb_is_a_dds(mem)) {
+ if (!imb_is_a_dds(mem, size)) {
return nullptr;
}
diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h
index ca74cbeaa74..9020529f210 100644
--- a/source/blender/imbuf/intern/dds/dds_api.h
+++ b/source/blender/imbuf/intern/dds/dds_api.h
@@ -26,7 +26,8 @@
extern "C" {
#endif
-int imb_is_a_dds(const unsigned char *mem); /* use only first 32 bytes of mem */
+/* use only first 32 bytes of mem */
+bool imb_is_a_dds(const unsigned char *mem, const size_t size);
bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags);
struct ImBuf *imb_load_dds(const unsigned char *mem,
size_t size,
diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c
index 6bf2e3ec8d3..c27ac5754c7 100644
--- a/source/blender/imbuf/intern/iris.c
+++ b/source/blender/imbuf/intern/iris.c
@@ -243,7 +243,7 @@ static void test_endian_zbuf(struct ImBuf *ibuf)
/* this one is only def-ed once, strangely... */
#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
-int imb_is_a_iris(const uchar *mem)
+bool imb_is_a_iris(const uchar *mem, size_t UNUSED(size))
{
return ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC));
}
@@ -271,7 +271,7 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors
return NULL;
}
- if (!imb_is_a_iris(mem)) {
+ if (!imb_is_a_iris(mem, size)) {
return NULL;
}
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c
index f0486852d6f..b964510b8db 100644
--- a/source/blender/imbuf/intern/jp2.c
+++ b/source/blender/imbuf/intern/jp2.c
@@ -80,7 +80,7 @@ static OPJ_CODEC_FORMAT format_from_header(const unsigned char mem[JP2_FILEHEADE
return OPJ_CODEC_UNKNOWN;
}
-int imb_is_a_jp2(const unsigned char *buf)
+bool imb_is_a_jp2(const unsigned char *buf, size_t UNUSED(size))
{
ret
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list