diff --git a/pdf.c b/pdf.c index 2cb5cd9c9ec6fff53023b4cd524afa4c917090d8..f8aa81009383ccbc24a5d98f210ca7da4d138d5f 100644 --- a/pdf.c +++ b/pdf.c @@ -1176,6 +1176,9 @@ act_rldstring(const HParseResult *p, void *u) * e.g. parentheses in streams don't count, unless for some reason they're parsed with the lparen rule.) * The validations make the parse fail if this nesting depth is exceeded. * Because currently there are no diagnostic messages, this can probably result in unexpected parses. + * + * validate_rparen, validate_array_end, and validate_dclose will make the parse fail if a respective closing token ( ')', ']', '>>' ) + * is encountered before an lparen, array_begin, or dopen. */ #define PAREN_MAX_NEST_DEPTH 256 @@ -1196,6 +1199,13 @@ act_lparen(const HParseResult *p, void *u) return H_MAKE_UINT(H_CAST_UINT(p->ast)); } +bool +validate_rparen(HParseResult *p, void *u) +{ + struct Env *aux = (struct Env*) u; + return aux->paren_nest_depth > 0; +} + HParsedToken* act_rparen(const HParseResult *p, void *u) { @@ -1224,6 +1234,13 @@ act_array_begin(const HParseResult *p, void *u) return H_MAKE_UINT(H_CAST_UINT(p->ast)); } +bool +validate_array_end(HParseResult *p, void *u) +{ + struct Env *aux = (struct Env*) u; + return aux->array_nest_depth > 0; +} + HParsedToken * act_array_end(const HParseResult *p, void *u) { @@ -1252,6 +1269,13 @@ act_dopen(const HParseResult *p, void *u) return H_MAKE_BYTES(H_CAST_BYTES(p->ast).token, H_CAST_BYTES(p->ast).len); } +bool +validate_dclose(HParseResult *p, void *u) +{ + struct Env *aux = (struct Env*) u; + return aux->dict_nest_depth > 0; +} + HParsedToken* act_dclose(const HParseResult *p, void *u) {