Skip to content

Commit 68a8bf4

Browse files
committed
better arg checking for hist_find_ndim
we were not checking the number of input bands move checks to _build thanks travisbell see #2634
1 parent 5c249e0 commit 68a8bf4

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
26/11/21 started 8.12.3
2+
- better arg checking for hist_find_ndim [travisbell]
3+
14
26/11/21 started 8.12.2
25
- make exif resuint optional and default to inch
36
- win: don't set create time on inappropriate file descriptors [lovell]

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# also update the version number in the m4 macros below
44

5-
AC_INIT([vips], [8.12.2], [vipsip@jiscmail.ac.uk])
5+
AC_INIT([vips], [8.12.3], [vipsip@jiscmail.ac.uk])
66
# required for gobject-introspection
77
AC_PREREQ([2.69])
88

@@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4])
1818
# user-visible library versioning
1919
m4_define([vips_major_version], [8])
2020
m4_define([vips_minor_version], [12])
21-
m4_define([vips_micro_version], [2])
21+
m4_define([vips_micro_version], [3])
2222
m4_define([vips_version],
2323
[vips_major_version.vips_minor_version.vips_micro_version])
2424

@@ -41,7 +41,7 @@ VIPS_LIBS=""
4141
# binary interface changed: increment current, reset revision to 0
4242
# binary interface changes backwards compatible?: increment age
4343
# binary interface changes not backwards compatible?: reset age to 0
44-
LIBRARY_REVISION=2
44+
LIBRARY_REVISION=3
4545
LIBRARY_CURRENT=56
4646
LIBRARY_AGE=14
4747

doc/libvips.actions

Whitespace-only changes.

libvips/arithmetic/hist_find_ndim.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* - small celanups
99
* 17/8/13
1010
* - redo as a class
11+
* 28/1/22 travisbell
12+
* - better arg checking
1113
*/
1214

1315
/*
@@ -57,8 +59,6 @@ struct _VipsHistFindNDim;
5759
typedef struct {
5860
struct _VipsHistFindNDim *ndim;
5961

60-
int bins;
61-
int max_val;
6262
unsigned int ***data;
6363
} Histogram;
6464

@@ -69,6 +69,10 @@ typedef struct _VipsHistFindNDim {
6969
*/
7070
int bins;
7171

72+
/* Max pixel value for this format.
73+
*/
74+
int max_val;
75+
7276
/* Main image histogram. Subhists accumulate to this.
7377
*/
7478
Histogram *hist;
@@ -89,7 +93,6 @@ static Histogram *
8993
histogram_new( VipsHistFindNDim *ndim )
9094
{
9195
VipsImage *in = VIPS_STATISTIC( ndim )->ready;
92-
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( ndim );
9396
int bins = ndim->bins;
9497

9598
/* How many dimensions do we need to allocate?
@@ -104,14 +107,6 @@ histogram_new( VipsHistFindNDim *ndim )
104107
return( NULL );
105108

106109
hist->ndim = ndim;
107-
hist->bins = bins;
108-
hist->max_val = in->BandFmt == VIPS_FORMAT_UCHAR ? 256 : 65536;
109-
if( bins < 1 ||
110-
bins > hist->max_val ) {
111-
vips_error( class->nickname,
112-
_( "bins out of range [1,%d]" ), hist->max_val );
113-
return( NULL );
114-
}
115110

116111
if( !(hist->data = VIPS_ARRAY( ndim, bins, unsigned int ** )) )
117112
return( NULL );
@@ -147,6 +142,25 @@ vips_hist_find_ndim_build( VipsObject *object )
147142
"out", vips_image_new(),
148143
NULL );
149144

145+
if( statistic->in ) {
146+
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( ndim );
147+
148+
if( statistic->in->Bands > 3 ) {
149+
vips_error( class->nickname,
150+
"%s", _( "image is not 1 - 3 bands" ) );
151+
return( -1 );
152+
}
153+
154+
ndim->max_val =
155+
statistic->in->BandFmt == VIPS_FORMAT_UCHAR ? 256 : 65536;
156+
if( ndim->bins < 1 ||
157+
ndim->bins > ndim->max_val ) {
158+
vips_error( class->nickname,
159+
_( "bins out of range [1,%d]" ), ndim->max_val );
160+
return( -1 );
161+
}
162+
}
163+
150164
/* main hist made on first thread start.
151165
*/
152166

@@ -204,9 +218,9 @@ vips_hist_find_ndim_stop( VipsStatistic *statistic, void *seq )
204218

205219
int i, j, k;
206220

207-
for( i = 0; i < hist->bins; i++ )
208-
for( j = 0; j < hist->bins; j++ )
209-
for( k = 0; k < hist->bins; k++ )
221+
for( i = 0; i < ndim->bins; i++ )
222+
for( j = 0; j < ndim->bins; j++ )
223+
for( k = 0; k < ndim->bins; k++ )
210224
if( hist->data[i] && hist->data[i][j] ) {
211225
hist->data[i][j][k] +=
212226
sub_hist->data[i][j][k];
@@ -236,9 +250,10 @@ vips_hist_find_ndim_scan( VipsStatistic *statistic, void *seq,
236250
int x, int y, void *in, int n )
237251
{
238252
Histogram *hist = (Histogram *) seq;
253+
VipsHistFindNDim *ndim = (VipsHistFindNDim *) statistic;
239254
VipsImage *im = statistic->ready;
240255
int nb = im->Bands;
241-
double scale = (double) (hist->max_val + 1) / hist->bins;
256+
double scale = (double) (ndim->max_val + 1) / ndim->bins;
242257
int i, j, k;
243258
int index[3];
244259

0 commit comments

Comments
 (0)