From 418813e80ed33f5b3d12805823213c414ceaeaf3 Mon Sep 17 00:00:00 2001 From: sxt1001 Date: Sat, 21 Nov 2020 16:00:25 +0800 Subject: [PATCH] fix test cases fail --- pre-CVE-2020-11538-1.patch | 181 ++++++++------- python-pillow.spec | 15 +- replace_copy_operations_with_memcpy.patch | 257 ++++++++++++++++++++++ 3 files changed, 356 insertions(+), 97 deletions(-) create mode 100644 replace_copy_operations_with_memcpy.patch diff --git a/pre-CVE-2020-11538-1.patch b/pre-CVE-2020-11538-1.patch index 088112a..337ca4d 100644 --- a/pre-CVE-2020-11538-1.patch +++ b/pre-CVE-2020-11538-1.patch @@ -3,22 +3,24 @@ From: Rolf Eike Beer Date: Sun, 1 Jul 2018 12:47:59 +0200 Subject: [PATCH] fix unaligned accesses by using memcpy() +https://github.com/python-pillow/Pillow/commit/7a4af2b7671b14163f61c7f88889fad66e50d77b + --- - src/_imaging.c | 31 ++++-- - src/libImaging/Access.c | 24 ++-- + src/_imaging.c | 31 +++-- + src/libImaging/Access.c | 16 +-- src/libImaging/Bands.c | 30 +++-- src/libImaging/ColorLUT.c | 10 +- src/libImaging/Convert.c | 165 +++++++++++++++------------ - src/libImaging/Filter.c | 32 ++++-- + src/libImaging/Filter.c | 33 ++++-- src/libImaging/Geometry.c | 18 ++- - src/libImaging/GetBBox.c | 26 +++-- - src/libImaging/Histo.c | 10 +- + src/libImaging/GetBBox.c | 24 ++-- + src/libImaging/Histo.c | 4 +- src/libImaging/Pack.c | 13 ++- src/libImaging/Point.c | 16 ++- src/libImaging/Resample.c | 30 +++-- src/libImaging/SgiRleDecode.c | 19 ++-- - src/libImaging/Unpack.c | 203 +++++++++++++++++----------------- - 14 files changed, 357 insertions(+), 270 deletions(-) + src/libImaging/Unpack.c | 209 +++++++++++++++++----------------- + 14 files changed, 353 insertions(+), 265 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index e4b31f1..56fa0b6 100644 @@ -111,63 +113,47 @@ index e4b31f1..56fa0b6 100644 } /* Max value for INT16 */ diff --git a/src/libImaging/Access.c b/src/libImaging/Access.c -index 292968f..47b0345 100644 +index 8d27a0a..15ffa11 100644 --- a/src/libImaging/Access.c +++ b/src/libImaging/Access.c -@@ -94,11 +94,11 @@ static void - get_pixel_16L(Imaging im, int x, int y, void* color) +@@ -95,8 +95,8 @@ get_pixel_16L(Imaging im, int x, int y, void* color) { UINT8* in = (UINT8*) &im->image[y][x+x]; -- UINT16* out = color; #ifdef WORDS_BIGENDIAN +- UINT16* out = color; - out[0] = in[0] + (in[1]<<8); + UINT16 out = in[0] + (in[1]<<8); + memcpy(color, &out, sizeof(out)); #else -- out[0] = *(UINT16*) in; -+ memcpy(color, in, sizeof(UINT16)); + memcpy(color, in, sizeof(UINT16)); #endif - } - -@@ -106,11 +106,11 @@ static void - get_pixel_16B(Imaging im, int x, int y, void* color) - { - UINT8* in = (UINT8*) &im->image[y][x+x]; -- UINT16* out = color; +@@ -109,8 +109,8 @@ get_pixel_16B(Imaging im, int x, int y, void* color) #ifdef WORDS_BIGENDIAN -- out[0] = *(UINT16*) in; -+ memcpy(color, in, sizeof(UINT16)); + memcpy(color, in, sizeof(UINT16)); #else +- UINT16* out = color; - out[0] = in[1] + (in[0]<<8); + UINT16 out = in[1] + (in[0]<<8); + memcpy(color, &out, sizeof(out)); #endif } -@@ -125,11 +125,11 @@ static void - get_pixel_32L(Imaging im, int x, int y, void* color) +@@ -125,8 +125,8 @@ get_pixel_32L(Imaging im, int x, int y, void* color) { UINT8* in = (UINT8*) &im->image[y][x*4]; -- INT32* out = color; #ifdef WORDS_BIGENDIAN +- INT32* out = color; - out[0] = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24); + INT32 out = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24); + memcpy(color, &out, sizeof(out)); #else -- out[0] = *(INT32*) in; -+ memcpy(color, in, sizeof(INT32)); + memcpy(color, in, sizeof(INT32)); #endif - } - -@@ -137,11 +137,11 @@ static void - get_pixel_32B(Imaging im, int x, int y, void* color) - { - UINT8* in = (UINT8*) &im->image[y][x*4]; -- INT32* out = color; +@@ -139,8 +139,8 @@ get_pixel_32B(Imaging im, int x, int y, void* color) #ifdef WORDS_BIGENDIAN -- out[0] = *(INT32*) in; -+ memcpy(color, in, sizeof(INT32)); + memcpy(color, in, sizeof(INT32)); #else +- INT32* out = color; - out[0] = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24); + INT32 out = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24); + memcpy(color, &out, sizeof(out)); @@ -607,7 +593,7 @@ index 39ddf87..b7b6a80 100644 static void diff --git a/src/libImaging/Filter.c b/src/libImaging/Filter.c -index 6e4a005..7d88cd7 100644 +index 64010ee..b033abf 100644 --- a/src/libImaging/Filter.c +++ b/src/libImaging/Filter.c @@ -122,26 +122,29 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, @@ -615,15 +601,14 @@ index 6e4a005..7d88cd7 100644 UINT8* in0 = (UINT8*) im->image[y]; UINT8* in1 = (UINT8*) im->image[y+1]; - UINT32* out = (UINT32*) imOut->image[y]; -+ UINT8* out = (UINT8*) imOut->image[y]; ++ UINT8* out = (UINT8*) imOut->image[y]; -- out[0] = ((UINT32*) in0)[0]; -+ memcpy(out, in0, sizeof(UINT32)); + memcpy(out, in0, sizeof(UINT32)); if (im->bands == 2) { for (x = 1; x < im->xsize-1; x++) { float ss0 = offset; float ss3 = offset; -+ UINT32 v; ++ UINT32 v; ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4); ss3 += KERNEL1x3(in1, x*4+3, &kernel[0], 4); ss0 += KERNEL1x3(in0, x*4+0, &kernel[3], 4); @@ -639,7 +624,7 @@ index 6e4a005..7d88cd7 100644 float ss0 = offset; float ss1 = offset; float ss2 = offset; -+ UINT32 v; ++ UINT32 v; ss0 += KERNEL1x3(in1, x*4+0, &kernel[0], 4); ss1 += KERNEL1x3(in1, x*4+1, &kernel[0], 4); ss2 += KERNEL1x3(in1, x*4+2, &kernel[0], 4); @@ -677,7 +662,15 @@ index 6e4a005..7d88cd7 100644 } } memcpy(imOut->image[y], im->image[y], im->linesize); -@@ -240,6 +246,7 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, +@@ -232,13 +238,14 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, + UINT8* in0 = (UINT8*) im->image[y]; + UINT8* in1 = (UINT8*) im->image[y+1]; + UINT8* in2 = (UINT8*) im->image[y+2]; +- UINT32* out = (UINT32*) imOut->image[y]; ++ UINT8* out = (UINT8*) imOut->image[y]; + + memcpy(out, in0, sizeof(UINT32) * 2); + if (im->bands == 2) { for (x = 2; x < im->xsize-2; x++) { float ss0 = offset; float ss3 = offset; @@ -685,7 +678,7 @@ index 6e4a005..7d88cd7 100644 ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4); ss3 += KERNEL1x5(in2, x*4+3, &kernel[0], 4); ss0 += KERNEL1x5(in1, x*4+0, &kernel[5], 4); -@@ -250,13 +257,15 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, +@@ -249,13 +256,15 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, ss3 += KERNEL1x5(in_1, x*4+3, &kernel[15], 4); ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4); ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4); @@ -702,7 +695,7 @@ index 6e4a005..7d88cd7 100644 ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4); ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4); ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4); -@@ -272,8 +281,9 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, +@@ -271,8 +280,9 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, ss0 += KERNEL1x5(in_2, x*4+0, &kernel[20], 4); ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4); ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4); @@ -713,7 +706,7 @@ index 6e4a005..7d88cd7 100644 } } else if (im->bands == 4) { for (x = 2; x < im->xsize-2; x++) { -@@ -281,6 +291,7 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, +@@ -280,6 +290,7 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, float ss1 = offset; float ss2 = offset; float ss3 = offset; @@ -721,7 +714,7 @@ index 6e4a005..7d88cd7 100644 ss0 += KERNEL1x5(in2, x*4+0, &kernel[0], 4); ss1 += KERNEL1x5(in2, x*4+1, &kernel[0], 4); ss2 += KERNEL1x5(in2, x*4+2, &kernel[0], 4); -@@ -301,12 +312,12 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, +@@ -300,12 +311,12 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, ss1 += KERNEL1x5(in_2, x*4+1, &kernel[20], 4); ss2 += KERNEL1x5(in_2, x*4+2, &kernel[20], 4); ss3 += KERNEL1x5(in_2, x*4+3, &kernel[20], 4); @@ -738,7 +731,7 @@ index 6e4a005..7d88cd7 100644 } memcpy(imOut->image[y], im->image[y], im->linesize); diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c -index 1d08728..52ca9fc 100644 +index 56a1aa3..cd64763 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -396,7 +396,7 @@ nearest_filter16(void* out, Imaging im, double xin, double yin) @@ -801,26 +794,29 @@ index 1d08728..52ca9fc 100644 } diff --git a/src/libImaging/GetBBox.c b/src/libImaging/GetBBox.c -index 3cfa42c..7f01e16 100644 +index 5cfb795..b63888f 100644 --- a/src/libImaging/GetBBox.c +++ b/src/libImaging/GetBBox.c -@@ -132,8 +132,8 @@ ImagingGetExtrema(Imaging im, void *extrema) - imax = in[x]; +@@ -147,7 +147,7 @@ ImagingGetExtrema(Imaging im, void *extrema) } } -- ((UINT8*) extrema)[0] = (UINT8) imin; -- ((UINT8*) extrema)[1] = (UINT8) imax; -+ memcpy(extrema, &imin, sizeof(imin)); + memcpy(extrema, &imin, sizeof(imin)); +- ((INT32*) extrema)[1] = imax; + memcpy(((char*)extrema) + sizeof(imin), &imax, sizeof(imax)); break; - case IMAGING_TYPE_INT32: - imin = imax = im->image32[0][0]; -@@ -165,18 +165,22 @@ ImagingGetExtrema(Imaging im, void *extrema) + case IMAGING_TYPE_FLOAT32: + fmin = fmax = ((FLOAT32*) im->image32[0])[0]; +@@ -161,22 +161,26 @@ ImagingGetExtrema(Imaging im, void *extrema) + } + } + memcpy(extrema, &fmin, sizeof(fmin)); +- ((FLOAT32*) extrema)[1] = fmax; ++ memcpy(((char*)extrema) + sizeof(fmin), &fmax, sizeof(fmax)); break; case IMAGING_TYPE_SPECIAL: if (strcmp(im->mode, "I;16") == 0) { - imin = imax = ((UINT16*) im->image8[0])[0]; -+ UINT16 v; ++ UINT16 v; + memcpy(&v, *im->image8, sizeof(v)); + imin = imax = v; for (y = 0; y < im->ysize; y++) { @@ -830,17 +826,16 @@ index 3cfa42c..7f01e16 100644 - imin = in[x]; - else if (imax < in[x]) - imax = in[x]; -- } + memcpy(&v, im->image[y] + x * sizeof(v), sizeof(v)); + if (imin > v) + imin = v; + else if (imax < v) + imax = v; -+ } + } } - ((UINT16*) extrema)[0] = (UINT16) imin; - ((UINT16*) extrema)[1] = (UINT16) imax; -+ v = (UINT16) imin; ++ v = (UINT16) imin; + memcpy(extrema, &v, sizeof(v)); + v = (UINT16) imax; + memcpy(((char*)extrema) + sizeof(v), &v, sizeof(v)); @@ -848,33 +843,27 @@ index 3cfa42c..7f01e16 100644 } /* FALL THROUGH */ diff --git a/src/libImaging/Histo.c b/src/libImaging/Histo.c -index 0bfc8df..7ba0ee0 100644 +index 887f09a..fb992e3 100644 --- a/src/libImaging/Histo.c +++ b/src/libImaging/Histo.c -@@ -124,8 +124,8 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) - return ImagingError_ValueError("min/max not given"); +@@ -125,7 +125,7 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) if (!im->xsize || !im->ysize) break; -- imin = ((INT32*) minmax)[0]; + memcpy(&imin, minmax, sizeof(imin)); - imax = ((INT32*) minmax)[1]; -+ memcpy(&imin, minmax, sizeof(imin)); + memcpy(&imax, ((char*)minmax) + sizeof(imin), sizeof(imax)); if (imin >= imax) break; ImagingSectionEnter(&cookie); -@@ -145,9 +145,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) - return ImagingError_ValueError("min/max not given"); +@@ -146,7 +146,7 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) if (!im->xsize || !im->ysize) break; -- fmin = ((FLOAT32*) minmax)[0]; + memcpy(&fmin, minmax, sizeof(fmin)); - fmax = ((FLOAT32*) minmax)[1]; -- if (fmin >= fmax) -+ memcpy(&fmin, minmax, sizeof(fmin)); + memcpy(&fmax, ((char*)minmax) + sizeof(fmin), sizeof(fmax)); -+ if (fmin >= fmax) + if (fmin >= fmax) break; ImagingSectionEnter(&cookie); - scale = 255.0F / (fmax - fmin); diff --git a/src/libImaging/Pack.c b/src/libImaging/Pack.c index 5c298c6..d18f31c 100644 --- a/src/libImaging/Pack.c @@ -1119,7 +1108,7 @@ index 39e7b3a..70b0ec5 100644 } diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c -index e9921d2..28c9cf1 100644 +index cdaba6e..485f984 100644 --- a/src/libImaging/Unpack.c +++ b/src/libImaging/Unpack.c @@ -32,7 +32,6 @@ @@ -1168,7 +1157,7 @@ index e9921d2..28c9cf1 100644 for (; i < pixels-1; i++) { - out[i] = MASK_UINT32_CHANNEL_3 | *(UINT32*)&in[0]; - in += 3; -+ UINT32 iv; ++ UINT32 iv; + memcpy(&iv, in, sizeof(iv)); + iv |= MASK_UINT32_CHANNEL_3; + memcpy(_out, &iv, sizeof(iv)); @@ -1177,12 +1166,27 @@ index e9921d2..28c9cf1 100644 for (; i < pixels; i++) { - out[i] = MAKE_UINT32(in[0], in[1], in[2], 255); - in += 3; -+ UINT32 iv = MAKE_UINT32(in[0], in[1], in[2], 255); ++ UINT32 iv = MAKE_UINT32(in[0], in[1], in[2], 255); + memcpy(_out, &iv, sizeof(iv)); + in += 3; _out += 4; } } +@@ -496,11 +498,11 @@ void + unpackRGB16L(UINT8* _out, const UINT8* in, int pixels) + { + int i; +- UINT32* out = (UINT32*) _out; + /* 16-bit RGB triplets, little-endian order */ + for (i = 0; i < pixels; i++) { +- out[i] = MAKE_UINT32(in[1], in[3], in[5], 255); +- in += 6; ++ UINT32 iv = MAKE_UINT32(in[1], in[3], in[5], 255); ++ memcpy(_out, &iv, sizeof(iv)); ++ in += 6; _out += 4; + } + } + @@ -508,11 +510,11 @@ void unpackRGB16B(UINT8* _out, const UINT8* in, int pixels) { @@ -1539,7 +1543,7 @@ index e9921d2..28c9cf1 100644 } } -@@ -1031,30 +1037,30 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ +@@ -1031,7 +1037,6 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ #ifdef WORDS_BIGENDIAN UINT8* tmp = (UINT8 *)&pixel; #endif @@ -1547,10 +1551,8 @@ index e9921d2..28c9cf1 100644 for (i = 0; i < pixels-1; i+=2) { pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4); #ifdef WORDS_BIGENDIAN - out[0] = tmp[1]; out[1] = tmp[0]; - #else -- out16[0] = pixel; -+ memcpy(out, &pixel, sizeof(pixel)); +@@ -1040,14 +1045,15 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ + memcpy(out, &pixel, sizeof(pixel)); #endif + out+=2; @@ -1568,14 +1570,6 @@ index e9921d2..28c9cf1 100644 } if (i == pixels-1) { pixel = (((UINT16) in[0]) << 4 ) + (in[1] >>4); - #ifdef WORDS_BIGENDIAN - out[0] = tmp[1]; out[1] = tmp[0]; - #else -- out16[0] = pixel; -+ memcpy(out, &pixel, sizeof(pixel)); - #endif - } - } @@ -1085,10 +1091,9 @@ static void copy4skip1(UINT8* _out, const UINT8* in, int pixels) { @@ -1589,11 +1583,9 @@ index e9921d2..28c9cf1 100644 } } -@@ -1096,10 +1101,9 @@ static void - copy4skip2(UINT8* _out, const UINT8* in, int pixels) - { +@@ -1098,8 +1103,8 @@ copy4skip2(UINT8* _out, const UINT8* in, int pixels) int i; -- UINT32* out = (UINT32*) _out; + UINT32* out = (UINT32*) _out; for (i = 0; i < pixels; i++) { - out[i] = *(UINT32*)&in[0]; - in += 6; @@ -1602,3 +1594,6 @@ index e9921d2..28c9cf1 100644 } } +-- +2.27.0 + diff --git a/python-pillow.spec b/python-pillow.spec index 367eda5..f9367f4 100644 --- a/python-pillow.spec +++ b/python-pillow.spec @@ -5,7 +5,7 @@ Name: python-pillow Version: 5.3.0 -Release: 7 +Release: 8 Summary: Python image processing library License: MIT URL: http://python-pillow.github.io/ @@ -18,9 +18,10 @@ Patch0003: 0003-CVE-2019-16865-4.patch Patch0004: CVE-2020-10378.patch Patch0005: CVE-2020-10177.patch Patch0006: CVE-2020-10994.patch -Patch0007: pre-CVE-2020-11538-1.patch -Patch0008: pre-CVE-2020-11538-2.patch -Patch0009: CVE-2020-11538.patch +Patch0010: replace_copy_operations_with_memcpy.patch +Patch0011: pre-CVE-2020-11538-1.patch +Patch0012: pre-CVE-2020-11538-2.patch +Patch0013: CVE-2020-11538.patch BuildRequires: freetype-devel ghostscript lcms2-devel libimagequant-devel libjpeg-devel BuildRequires: libtiff-devel libwebp-devel openjpeg2-devel tk-devel zlib-devel @@ -174,6 +175,12 @@ popd %doc docs/_build_py3/html %changelog +* Sat Nov 21 2020 shixuantong - 5.3.0-8 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix test cases fail + * Sun Sep 13 2020 shixuantong - 5.3.0-7 - Type:cves - ID:CVE-2020-11538 diff --git a/replace_copy_operations_with_memcpy.patch b/replace_copy_operations_with_memcpy.patch new file mode 100644 index 0000000..809a6ff --- /dev/null +++ b/replace_copy_operations_with_memcpy.patch @@ -0,0 +1,257 @@ +From 220bfee19a98a0d5b3fe5a52b51df16dd459c397 Mon Sep 17 00:00:00 2001 +From: Rolf Eike Beer +Date: Fri, 29 Jun 2018 22:33:08 +0200 +Subject: [PATCH] replace copy operations with memcpy() + +https://github.com/python-pillow/Pillow/commit/220bfee19a98a0d5b3fe5a52b51df16dd459c397 + +This replaces trivial instances where a copy from one pointer to the other +involves no further calculations or casts. The compiler will optimize this to +whatever the platform offers. +--- + src/libImaging/Access.c | 35 +++++++++++++---------------------- + src/libImaging/Draw.c | 3 +-- + src/libImaging/Filter.c | 5 ++--- + src/libImaging/Geometry.c | 2 +- + src/libImaging/GetBBox.c | 4 ++-- + src/libImaging/Histo.c | 4 ++-- + src/libImaging/Unpack.c | 4 ++-- + 7 files changed, 23 insertions(+), 34 deletions(-) + +diff --git a/src/libImaging/Access.c b/src/libImaging/Access.c +index 292968f..8d27a0a 100644 +--- a/src/libImaging/Access.c ++++ b/src/libImaging/Access.c +@@ -94,11 +94,11 @@ static void + get_pixel_16L(Imaging im, int x, int y, void* color) + { + UINT8* in = (UINT8*) &im->image[y][x+x]; +- UINT16* out = color; + #ifdef WORDS_BIGENDIAN ++ UINT16* out = color; + out[0] = in[0] + (in[1]<<8); + #else +- out[0] = *(UINT16*) in; ++ memcpy(color, in, sizeof(UINT16)); + #endif + } + +@@ -106,10 +106,10 @@ static void + get_pixel_16B(Imaging im, int x, int y, void* color) + { + UINT8* in = (UINT8*) &im->image[y][x+x]; +- UINT16* out = color; + #ifdef WORDS_BIGENDIAN +- out[0] = *(UINT16*) in; ++ memcpy(color, in, sizeof(UINT16)); + #else ++ UINT16* out = color; + out[0] = in[1] + (in[0]<<8); + #endif + } +@@ -117,19 +117,18 @@ get_pixel_16B(Imaging im, int x, int y, void* color) + static void + get_pixel_32(Imaging im, int x, int y, void* color) + { +- INT32* out = color; +- out[0] = im->image32[y][x]; ++ memcpy(color, &im->image32[y][x], sizeof(INT32)); + } + + static void + get_pixel_32L(Imaging im, int x, int y, void* color) + { + UINT8* in = (UINT8*) &im->image[y][x*4]; +- INT32* out = color; + #ifdef WORDS_BIGENDIAN ++ INT32* out = color; + out[0] = in[0] + (in[1]<<8) + (in[2]<<16) + (in[3]<<24); + #else +- out[0] = *(INT32*) in; ++ memcpy(color, in, sizeof(INT32)); + #endif + } + +@@ -137,10 +136,10 @@ static void + get_pixel_32B(Imaging im, int x, int y, void* color) + { + UINT8* in = (UINT8*) &im->image[y][x*4]; +- INT32* out = color; + #ifdef WORDS_BIGENDIAN +- out[0] = *(INT32*) in; ++ memcpy(color, in, sizeof(INT32)); + #else ++ INT32* out = color; + out[0] = in[3] + (in[2]<<8) + (in[1]<<16) + (in[0]<<24); + #endif + } +@@ -153,7 +152,7 @@ put_pixel(Imaging im, int x, int y, const void* color) + if (im->image8) + im->image8[y][x] = *((UINT8*) color); + else +- im->image32[y][x] = *((INT32*) color); ++ memcpy(&im->image32[y][x], color, sizeof(INT32)); + } + + static void +@@ -165,10 +164,7 @@ put_pixel_8(Imaging im, int x, int y, const void* color) + static void + put_pixel_16L(Imaging im, int x, int y, const void* color) + { +- const char* in = color; +- UINT8* out = (UINT8*) &im->image8[y][x+x]; +- out[0] = in[0]; +- out[1] = in[1]; ++ memcpy(&im->image8[y][x+x], color, 2); + } + + static void +@@ -183,12 +179,7 @@ put_pixel_16B(Imaging im, int x, int y, const void* color) + static void + put_pixel_32L(Imaging im, int x, int y, const void* color) + { +- const char* in = color; +- UINT8* out = (UINT8*) &im->image8[y][x*4]; +- out[0] = in[0]; +- out[1] = in[1]; +- out[2] = in[2]; +- out[3] = in[3]; ++ memcpy(&im->image8[y][x*4], color, 4); + } + + static void +@@ -205,7 +196,7 @@ put_pixel_32B(Imaging im, int x, int y, const void* color) + static void + put_pixel_32(Imaging im, int x, int y, const void* color) + { +- im->image32[y][x] = *((INT32*) color); ++ memcpy(&im->image32[y][x], color, sizeof(INT32)); + } + + void +diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c +index d0f374f..3b1ae0c 100644 +--- a/src/libImaging/Draw.c ++++ b/src/libImaging/Draw.c +@@ -40,7 +40,6 @@ + #define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v)) + + #define INK8(ink) (*(UINT8*)ink) +-#define INK32(ink) (*(INT32*)ink) + + /* + * Rounds around zero (up=away from zero, down=torwards zero) +@@ -555,7 +554,7 @@ DRAW draw32rgba = { point32rgba, hline32rgba, line32rgba, polygon32rgba }; + ink = INK8(ink_);\ + } else {\ + draw = (op) ? &draw32rgba : &draw32; \ +- ink = INK32(ink_);\ ++ memcpy(&ink, ink_, sizeof(ink)); \ + } + + int +diff --git a/src/libImaging/Filter.c b/src/libImaging/Filter.c +index 6e4a005..64010ee 100644 +--- a/src/libImaging/Filter.c ++++ b/src/libImaging/Filter.c +@@ -124,7 +124,7 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, + UINT8* in1 = (UINT8*) im->image[y+1]; + UINT32* out = (UINT32*) imOut->image[y]; + +- out[0] = ((UINT32*) in0)[0]; ++ memcpy(out, in0, sizeof(UINT32)); + if (im->bands == 2) { + for (x = 1; x < im->xsize-1; x++) { + float ss0 = offset; +@@ -234,8 +234,7 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel, + UINT8* in2 = (UINT8*) im->image[y+2]; + UINT32* out = (UINT32*) imOut->image[y]; + +- out[0] = ((UINT32*) in0)[0]; +- out[1] = ((UINT32*) in0)[1]; ++ memcpy(out, in0, sizeof(UINT32) * 2); + if (im->bands == 2) { + for (x = 2; x < im->xsize-2; x++) { + float ss0 = offset; +diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c +index 1d08728..56a1aa3 100644 +--- a/src/libImaging/Geometry.c ++++ b/src/libImaging/Geometry.c +@@ -407,7 +407,7 @@ nearest_filter32(void* out, Imaging im, double xin, double yin) + int y = COORD(yin); + if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) + return 0; +- ((INT32*)out)[0] = im->image32[y][x]; ++ memcpy(out, &im->image32[y][x], sizeof(INT32)); + return 1; + } + +diff --git a/src/libImaging/GetBBox.c b/src/libImaging/GetBBox.c +index 3cfa42c..5cfb795 100644 +--- a/src/libImaging/GetBBox.c ++++ b/src/libImaging/GetBBox.c +@@ -146,7 +146,7 @@ ImagingGetExtrema(Imaging im, void *extrema) + imax = in[x]; + } + } +- ((INT32*) extrema)[0] = imin; ++ memcpy(extrema, &imin, sizeof(imin)); + ((INT32*) extrema)[1] = imax; + break; + case IMAGING_TYPE_FLOAT32: +@@ -160,7 +160,7 @@ ImagingGetExtrema(Imaging im, void *extrema) + fmax = in[x]; + } + } +- ((FLOAT32*) extrema)[0] = fmin; ++ memcpy(extrema, &fmin, sizeof(fmin)); + ((FLOAT32*) extrema)[1] = fmax; + break; + case IMAGING_TYPE_SPECIAL: +diff --git a/src/libImaging/Histo.c b/src/libImaging/Histo.c +index 0bfc8df..887f09a 100644 +--- a/src/libImaging/Histo.c ++++ b/src/libImaging/Histo.c +@@ -124,7 +124,7 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) + return ImagingError_ValueError("min/max not given"); + if (!im->xsize || !im->ysize) + break; +- imin = ((INT32*) minmax)[0]; ++ memcpy(&imin, minmax, sizeof(imin)); + imax = ((INT32*) minmax)[1]; + if (imin >= imax) + break; +@@ -145,7 +145,7 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax) + return ImagingError_ValueError("min/max not given"); + if (!im->xsize || !im->ysize) + break; +- fmin = ((FLOAT32*) minmax)[0]; ++ memcpy(&fmin, minmax, sizeof(fmin)); + fmax = ((FLOAT32*) minmax)[1]; + if (fmin >= fmax) + break; +diff --git a/src/libImaging/Unpack.c b/src/libImaging/Unpack.c +index e9921d2..cdaba6e 100644 +--- a/src/libImaging/Unpack.c ++++ b/src/libImaging/Unpack.c +@@ -1037,7 +1037,7 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ + #ifdef WORDS_BIGENDIAN + out[0] = tmp[1]; out[1] = tmp[0]; + #else +- out16[0] = pixel; ++ memcpy(out, &pixel, sizeof(pixel)); + #endif + + pixel = (((UINT16) (in[1] & 0x0F)) << 8) + in[2]; +@@ -1054,7 +1054,7 @@ unpackI12_I16(UINT8* out, const UINT8* in, int pixels){ + #ifdef WORDS_BIGENDIAN + out[0] = tmp[1]; out[1] = tmp[0]; + #else +- out16[0] = pixel; ++ memcpy(out, &pixel, sizeof(pixel)); + #endif + } + } +-- +2.27.0 + -- Gitee