xmlwf: Support disabling reparse deferral

Rebased-and-adapted-by: Snild Dolkow <snild@sony.com>
This commit is contained in:
Sebastian Pipping 2023-11-09 19:14:14 +01:00 committed by Snild Dolkow
parent 8f8aaf5c8e
commit 09fdf998e7
2 changed files with 24 additions and 0 deletions

View file

@ -918,6 +918,9 @@ usage(const XML_Char *prog, int rc) {
T(" -a FACTOR set maximum tolerated [a]mplification factor (default: 100.0)\n")
T(" -b BYTES set number of output [b]ytes needed to activate (default: 8 MiB)\n")
T("\n")
T("reparse deferral:\n")
T(" -q disable reparse deferral, and allow [q]uadratic parse runtime with large tokens\n")
T("\n")
T("info arguments:\n")
T(" -h, --help show this [h]elp message and exit\n")
T(" -v, --version show program's [v]ersion number and exit\n")
@ -973,6 +976,8 @@ tmain(int argc, XML_Char **argv) {
unsigned long long attackThresholdBytes = 0;
XML_Bool attackThresholdGiven = XML_FALSE;
XML_Bool disableDeferral = XML_FALSE;
int exitCode = XMLWF_EXIT_SUCCESS;
enum XML_ParamEntityParsing paramEntityParsing
= XML_PARAM_ENTITY_PARSING_NEVER;
@ -1125,6 +1130,11 @@ tmain(int argc, XML_Char **argv) {
#endif
break;
}
case T('q'): {
disableDeferral = XML_TRUE;
j++;
break;
}
case T('\0'):
if (j > 1) {
i++;
@ -1171,6 +1181,16 @@ tmain(int argc, XML_Char **argv) {
#endif
}
if (disableDeferral) {
const XML_Bool success = XML_SetReparseDeferralEnabled(parser, XML_FALSE);
if (! success) {
// This prevents tperror(..) from reporting misleading "[..]: Success"
errno = EINVAL;
tperror(T("Failed to disable reparse deferral"));
exit(XMLWF_EXIT_INTERNAL_ERROR);
}
}
if (requireStandalone)
XML_SetNotStandaloneHandler(parser, notStandalone);
XML_SetParamEntityParsing(parser, paramEntityParsing);

View file

@ -82,6 +82,10 @@ billion_laughs.add_argument('-a', metavar='FACTOR',
help='set maximum tolerated [a]mplification factor (default: 100.0)')
billion_laughs.add_argument('-b', metavar='BYTES', help='set number of output [b]ytes needed to activate (default: 8 MiB)')
reparse_deferral = parser.add_argument_group('reparse deferral')
reparse_deferral.add_argument('-q', metavar='FACTOR',
help='disable reparse deferral, and allow [q]uadratic parse runtime with large tokens')
parser.add_argument('files', metavar='FILE', nargs='*', help='file to process (default: STDIN)')
info = parser.add_argument_group('info arguments')