Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions ext/gd/libgd/gd_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#else
# include <unistd.h>
#endif
#include <math.h>
#include <stdlib.h>
#include <time.h>

Expand All @@ -20,6 +21,20 @@
/* Begin filters function */
#define GET_PIXEL_FUNCTION(src)(src->trueColor?gdImageGetTrueColorPixel:gdImageGetPixel)

static int gdClampFloatToByte(float value)
{
if (!isfinite(value)) {
return value > 0.0f ? 255 : 0;
}
if (value > 255.0f) {
return 255;
}
if (value < 0.0f) {
return 0;
}
return (int)value;
}

#ifdef _WIN32
# define GD_SCATTER_SEED() (unsigned int)(time(0) * GetCurrentProcessId())
#else
Expand Down Expand Up @@ -417,6 +432,7 @@ int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, flo

for ( y=0; y<src->sy; y++) {
for(x=0; x<src->sx; x++) {
int new_ri, new_gi, new_bi;
new_r = new_g = new_b = 0;
pxl = f(srcback, x, y);
new_a = gdImageAlpha(srcback, pxl);
Expand All @@ -435,13 +451,13 @@ int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, flo
new_g = (new_g/filter_div)+offset;
new_b = (new_b/filter_div)+offset;

new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
new_ri = gdClampFloatToByte(new_r);
new_gi = gdClampFloatToByte(new_g);
new_bi = gdClampFloatToByte(new_b);

new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
new_pxl = gdImageColorAllocateAlpha(src, new_ri, new_gi, new_bi, new_a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
new_pxl = gdImageColorClosestAlpha(src, new_ri, new_gi, new_bi, new_a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
Expand Down
32 changes: 32 additions & 0 deletions ext/gd/tests/gh19666.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
GH-19666 (Unexpected nan value in imageconvolution)
--EXTENSIONS--
gd
--FILE--
<?php
$image = imagecreatetruecolor(180, 30);

$gaussian = array(
array(1.0, 2.0, 1.0),
array(2.0, 4.0, 2.0),
array(1.0, 2.0, -INF)
);

var_dump(imageconvolution($image, $gaussian, 16, 0));

$rgba = imagecolorat($image, 0, 0);
$colors = imagecolorsforindex($image, $rgba);
var_dump($colors);
?>
--EXPECT--
bool(true)
array(4) {
["red"]=>
int(0)
["green"]=>
int(0)
["blue"]=>
int(0)
["alpha"]=>
int(0)
}
Binary file modified ext/zlib/tests/bug55544-win.phpt
Binary file not shown.
18 changes: 0 additions & 18 deletions ext/zlib/tests/data/func.inc

This file was deleted.

5 changes: 2 additions & 3 deletions ext/zlib/tests/gzencode_variation2-win32.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ zlib
if( substr(PHP_OS, 0, 3) != "WIN" ) {
die("skip.. only for Windows");
}
include 'data/func.inc';
if (version_compare(get_zlib_version(), "1.2.11") < 0) {
die("skip - at least zlib 1.2.11 required, got " . get_zlib_version());
if (version_compare(ZLIB_VERSION, "1.2.11") < 0) {
die("skip - at least zlib 1.2.11 required, got " . ZLIB_VERSION);
}
?>
--FILE--
Expand Down
3 changes: 1 addition & 2 deletions ext/zlib/tests/gzgetc_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Test function gzgetc() by calling it with its expected arguments zlib 1.2.5
zlib
--SKIPIF--
<?php
include 'data/func.inc';
if (version_compare(get_zlib_version(), '1.2.5') > 0) {
if (version_compare(ZLIB_VERSION, '1.2.5') > 0) {
die('skip - only for zlib <= 1.2.5');
}
?>
Expand Down
4 changes: 1 addition & 3 deletions ext/zlib/tests/gzgetc_basic_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ Test function gzgetc() by calling it with its expected arguments zlib 1.2.7
zlib
--SKIPIF--
<?php

include 'data/func.inc';
if (version_compare(get_zlib_version(), '1.2.7') < 0) {
if (version_compare(ZLIB_VERSION, '1.2.7') < 0) {
die('skip - only for zlib >= 1.2.7');
}
?>
Expand Down
48 changes: 22 additions & 26 deletions main/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
#include <stdlib.h>
#include "php_getopt.h"

#define OPTERRCOLON (1)
#define OPTERRNF (2)
#define OPTERRARG (3)
#define OPTERRCOLON 1
#define OPTERRNF 2
#define OPTERRARG 3

// Print error message to stderr and return -2 to distinguish it from '?' command line option.
static int php_opt_error(int argc, char * const *argv, int optint, int optchr, int err, int show_err) /* {{{ */
{
if (show_err)
{
if (show_err) {
fprintf(stderr, "Error in argument %d, char %d: ", optint, optchr+1);
switch(err)
{
Expand Down Expand Up @@ -61,28 +60,26 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
*optarg = NULL;
}

if(prev_optarg && prev_optarg != optarg) {
if (prev_optarg && prev_optarg != optarg) {
/* reset the state */
optchr = 0;
dash = 0;
}
prev_optarg = optarg;

if (*optind >= argc) {
return(EOF);
return EOF;
}
if (!dash) {
if ((argv[*optind][0] != '-')) {
return(EOF);
} else {
if (!argv[*optind][1])
{
/*
* use to specify stdin. Need to let pgm process this and
* the following args
*/
return(EOF);
}
if (argv[*optind][0] != '-') {
return EOF;
}
if (!argv[*optind][1]) {
/*
* use to specify stdin. Need to let pgm process this and
* the following args
*/
return EOF;
}
}
if ((argv[*optind][0] == '-') && (argv[*optind][1] == '-')) {
Expand All @@ -92,7 +89,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
/* '--' indicates end of args if not followed by a known long option name */
if (argv[*optind][2] == '\0') {
(*optind)++;
return(EOF);
return EOF;
}

arg_start = 2;
Expand All @@ -109,7 +106,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
php_optidx++;
if (opts[php_optidx].opt_char == '-') {
(*optind)++;
return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
return php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err);
} else if (opts[php_optidx].opt_name && !strncmp(&argv[*optind][2], opts[php_optidx].opt_name, arg_end) && arg_end == strlen(opts[php_optidx].opt_name)) {
break;
}
Expand All @@ -127,7 +124,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
if (argv[*optind][optchr] == ':') {
dash = 0;
(*optind)++;
return (php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err));
return php_opt_error(argc, argv, *optind-1, optchr, OPTERRCOLON, show_err);
}
arg_start = 1 + optchr;
}
Expand All @@ -145,7 +142,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
optchr++;
arg_start++;
}
return(php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err));
return php_opt_error(argc, argv, errind, errchr, OPTERRNF, show_err);
} else if (argv[*optind][optchr] == opts[php_optidx].opt_char) {
break;
}
Expand All @@ -160,7 +157,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
if (*optind == argc) {
/* Was the value required or is it optional? */
if (opts[php_optidx].need_param == 1) {
return(php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err));
return php_opt_error(argc, argv, *optind-1, optchr, OPTERRARG, show_err);
}
/* Optional value is not supported with -<arg> <val> style */
} else if (opts[php_optidx].need_param == 1) {
Expand All @@ -178,8 +175,7 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
} else {
/* multiple options specified as one (exclude long opts) */
if (arg_start >= 2 && !((argv[*optind][0] == '-') && (argv[*optind][1] == '-'))) {
if (!argv[*optind][optchr+1])
{
if (!argv[*optind][optchr+1]) {
dash = 0;
(*optind)++;
} else {
Expand All @@ -191,6 +187,6 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
return opts[php_optidx].opt_char;
}
assert(0);
return(0); /* never reached */
return 0; /* never reached */
}
/* }}} */