Accepting request 1004988 from home:Andreas_Schwab:Factory

- ppmforge-fix-overflow.patch: Fix arithmetic overflow in ppmforge
- ppmforge-test.patch: removed

OBS-URL: https://build.opensuse.org/request/show/1004988
OBS-URL: https://build.opensuse.org/package/show/graphics/netpbm?expand=0&rev=139
This commit is contained in:
David Anes 2022-09-20 15:08:02 +00:00 committed by Git OBS Bridge
parent 6e3cf01f88
commit b1a68b1c78
4 changed files with 190 additions and 18 deletions

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Sun Sep 18 09:15:29 UTC 2022 - Andreas Schwab <schwab@suse.de>
- ppmforge-fix-overflow.patch: Fix arithmetic overflow in ppmforge
- ppmforge-test.patch: removed
-------------------------------------------------------------------
Wed Sep 14 13:15:23 UTC 2022 - Andreas Schwab <schwab@suse.de>

View File

@ -47,8 +47,8 @@ Patch6: signed-char.patch
Patch7: big-endian.patch
# bsc#1144255 disable jpeg2k support due to removal of jasper
Patch8: netpbm-disable-jasper.patch
# PATCH-FIX-UPSTREAM fix ppmforge test to avoid float overflow
Patch9: ppmforge-test.patch
# PATCH-FIX-UPSTREAM fix arithmetic overflow in ppmforge (https://sourceforge.net/p/netpbm/code/4428/)
Patch9: ppmforge-fix-overflow.patch
BuildRequires: flex
BuildRequires: libjpeg-devel
BuildRequires: libpng-devel

182
ppmforge-fix-overflow.patch Normal file
View File

@ -0,0 +1,182 @@
Index: netpbm/generator/ppmforge.c
===================================================================
--- netpbm/generator/ppmforge.c (revision 4427)
+++ netpbm/generator/ppmforge.c (revision 4428)
@@ -241,7 +241,7 @@
static void
-fourn(float * const data,
+fourn(double * const data,
const int * const nn,
int const ndim,
int const isign) {
@@ -272,7 +272,7 @@
int i1, i2, i3;
int i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
int ibit, idim, k1, k2, n, nprev, nrem, ntot;
- float tempi, tempr;
+ double tempi, tempr;
double theta, wi, wpi, wpr, wr, wtemp;
#define SWAP(a,b) tempr=(a); (a) = (b); (b) = tempr
@@ -401,7 +401,7 @@
static void
-spectralsynth(float ** const x,
+spectralsynth(double ** const aP,
unsigned int const n,
double const h,
struct Gauss * const gaussP) {
@@ -411,18 +411,20 @@
This algorithm is given under the name SpectralSynthesisFM2D on page 108 of
Peitgen & Saupe.
-----------------------------------------------------------------------------*/
- unsigned bl;
+ unsigned int const bl = ((((unsigned long) n) * n) + 1) * 2;
+
int i, j, i0, j0, nsize[3];
double rad, phase, rcos, rsin;
- float *a;
+ double * a;
- bl = ((((unsigned long) n) * n) + 1) * 2 * sizeof(float);
- a = (float *) calloc(bl, 1);
- if (a == (float *) 0) {
- pm_error("Cannot allocate %d x %d result array (% d bytes).",
+ MALLOCARRAY(a, bl);
+
+ if (!a) {
+ pm_error("Cannot allocate %u x %u result array (%u doubles).",
n, n, bl);
}
- *x = a;
+ for (i = 0; i < bl; ++i)
+ a[i] = 0.0; /* initial value */
for (i = 0; i <= n / 2; i++) {
for (j = 0; j <= n / 2; j++) {
@@ -463,6 +465,8 @@
nsize[0] = 0;
nsize[1] = nsize[2] = n; /* Dimension of frequency domain array */
fourn(a, nsize, 2, -1); /* Take inverse 2D Fourier transform */
+
+ *aP = a;
}
@@ -572,9 +576,9 @@
static unsigned char *
-makeCp(float * const a,
- unsigned int const n,
- pixval const maxval) {
+makeCp(const double * const a,
+ unsigned int const n,
+ pixval const maxval) {
/* Prescale the grid points into intensities. */
@@ -587,7 +591,7 @@
if (cp == NULL)
pm_error("Unable to allocate %u bytes for cp array", n);
- ap = cp;
+ ap = cp; /* initial value */
{
unsigned int i;
for (i = 0; i < n; i++) {
@@ -603,7 +607,7 @@
static void
createPlanetStuff(bool const clouds,
- float * const a,
+ const double * const a,
unsigned int const n,
double ** const uP,
double ** const u1P,
@@ -977,7 +981,7 @@
static void
genplanet(bool const stars,
bool const clouds,
- float * const a,
+ const double * const a,
unsigned int const cols,
unsigned int const rows,
unsigned int const n,
@@ -1052,7 +1056,7 @@
static void
-applyPowerLawScaling(float * const a,
+applyPowerLawScaling(double * const a,
int const meshsize,
double const powscale) {
@@ -1065,7 +1069,7 @@
for (j = 0; j < meshsize; j++) {
double const r = Real(a, i, j);
if (r > 0)
- Real(a, i, j) = pow(r, powscale);
+ Real(a, i, j) = MIN(hugeVal, pow(r, powscale));
}
}
}
@@ -1074,10 +1078,10 @@
static void
-computeExtremeReal(const float * const a,
- int const meshsize,
- double * const rminP,
- double * const rmaxP) {
+computeExtremeReal(const double * const a,
+ int const meshsize,
+ double * const rminP,
+ double * const rmaxP) {
/* Compute extrema for autoscaling. */
@@ -1103,8 +1107,8 @@
static void
-replaceWithSpread(float * const a,
- int const meshsize) {
+replaceWithSpread(double * const a,
+ int const meshsize) {
/*----------------------------------------------------------------------------
Replace the real part of each element of the 'a' array with a
measure of how far the real is from the middle; sort of a standard
@@ -1138,7 +1142,7 @@
/*----------------------------------------------------------------------------
Make a planet.
-----------------------------------------------------------------------------*/
- float * a;
+ double * a;
bool error;
struct Gauss gauss;
@@ -1149,7 +1153,7 @@
error = FALSE;
} else {
spectralsynth(&a, meshsize, 3.0 - fracdim, &gauss);
- if (a == NULL) {
+ if (!a) {
error = TRUE;
} else {
applyPowerLawScaling(a, meshsize, powscale);
Index: netpbm/test/ppmforge.test
===================================================================
--- netpbm/test/ppmforge.test (revision 4427)
+++ netpbm/test/ppmforge.test (revision 4428)
@@ -47,6 +47,6 @@
-inclination 9 -hour 12 -power 200 > ${test_ppm}
ppmforge -seed 1 -stars 0 -ice 0.01 \
-inclination 10 -hour 12 -power 200 | \
- pnmpsnr -target1=53.89 -target2=49.38 -target3=65.15 - ${test_ppm}
+ pnmpsnr -target1=46.07 -target2=52.00 -target3=67.77 - ${test_ppm}
rm ${test_ppm}

View File

@ -1,16 +0,0 @@
Index: netpbm-10.96.4/test/ppmforge.test
===================================================================
--- netpbm-10.96.4.orig/test/ppmforge.test
+++ netpbm-10.96.4/test/ppmforge.test
@@ -44,9 +44,9 @@ rm ${test_ppm}
echo "Test 5."
ppmforge -seed 1 -stars 0 -ice 0.01 \
- -inclination 9 -hour 12 -power 200 > ${test_ppm}
+ -inclination 9 -hour 12 -power 20 > ${test_ppm}
ppmforge -seed 1 -stars 0 -ice 0.01 \
- -inclination 10 -hour 12 -power 200 | \
+ -inclination 10 -hour 12 -power 20 | \
pnmpsnr -target1=53.89 -target2=49.38 -target3=65.15 - ${test_ppm}
rm ${test_ppm}