mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
Allow the json_decode() depth to be any size, but keep the static one around for now. It might make sense to allow an unbound depth.
This commit is contained in:
parent
5af0cbef65
commit
1c1ba8cc06
3 changed files with 14 additions and 7 deletions
|
@ -247,6 +247,11 @@ new_JSON_parser(int depth)
|
||||||
jp->top = -1;
|
jp->top = -1;
|
||||||
jp->error_code = PHP_JSON_ERROR_NONE;
|
jp->error_code = PHP_JSON_ERROR_NONE;
|
||||||
jp->stack = (int*)ecalloc(depth, sizeof(int));
|
jp->stack = (int*)ecalloc(depth, sizeof(int));
|
||||||
|
if (depth > JSON_PARSER_DEFAULT_DEPTH) {
|
||||||
|
jp->the_zstack = (zval **)safe_emalloc(depth, sizeof(zval), 0);
|
||||||
|
} else {
|
||||||
|
jp->the_zstack = &jp->the_static_zstack[0];
|
||||||
|
}
|
||||||
push(jp, MODE_DONE);
|
push(jp, MODE_DONE);
|
||||||
return jp;
|
return jp;
|
||||||
}
|
}
|
||||||
|
@ -258,6 +263,9 @@ int
|
||||||
free_JSON_parser(JSON_parser jp)
|
free_JSON_parser(JSON_parser jp)
|
||||||
{
|
{
|
||||||
efree((void*)jp->stack);
|
efree((void*)jp->stack);
|
||||||
|
if (jp->the_zstack != &jp->the_static_zstack[0]) {
|
||||||
|
efree(jp->the_zstack);
|
||||||
|
}
|
||||||
efree((void*)jp);
|
efree((void*)jp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "php.h"
|
#include "php.h"
|
||||||
#include "ext/standard/php_smart_str.h"
|
#include "ext/standard/php_smart_str.h"
|
||||||
|
|
||||||
#define JSON_PARSER_MAX_DEPTH 512
|
#define JSON_PARSER_DEFAULT_DEPTH 512
|
||||||
|
|
||||||
typedef struct JSON_parser_struct {
|
typedef struct JSON_parser_struct {
|
||||||
int state;
|
int state;
|
||||||
|
@ -14,8 +14,8 @@ typedef struct JSON_parser_struct {
|
||||||
int top;
|
int top;
|
||||||
int error_code;
|
int error_code;
|
||||||
int* stack;
|
int* stack;
|
||||||
zval *the_zstack[JSON_PARSER_MAX_DEPTH];
|
zval **the_zstack;
|
||||||
|
zval *the_static_zstack[JSON_PARSER_DEFAULT_DEPTH];
|
||||||
} * JSON_parser;
|
} * JSON_parser;
|
||||||
|
|
||||||
enum error_codes {
|
enum error_codes {
|
||||||
|
|
|
@ -507,7 +507,7 @@ static PHP_FUNCTION(json_decode)
|
||||||
int str_len, utf16_len;
|
int str_len, utf16_len;
|
||||||
zend_uchar str_type;
|
zend_uchar str_type;
|
||||||
zend_bool assoc = 0; /* return JS objects as PHP objects by default */
|
zend_bool assoc = 0; /* return JS objects as PHP objects by default */
|
||||||
long depth = JSON_PARSER_MAX_DEPTH;
|
long depth = JSON_PARSER_DEFAULT_DEPTH;
|
||||||
zval *z;
|
zval *z;
|
||||||
unsigned short *utf16;
|
unsigned short *utf16;
|
||||||
JSON_parser jp;
|
JSON_parser jp;
|
||||||
|
@ -535,9 +535,8 @@ static PHP_FUNCTION(json_decode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* can be removed once we remove the max depth limit */
|
if (depth <= 0) {
|
||||||
if (depth <= 0 || depth > JSON_PARSER_MAX_DEPTH) {
|
depth = JSON_PARSER_DEFAULT_DEPTH;
|
||||||
depth = JSON_PARSER_MAX_DEPTH;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ALLOC_INIT_ZVAL(z);
|
ALLOC_INIT_ZVAL(z);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue