Skip to content

support for long lines in filter files - #123

Open
teruteru128 wants to merge 2 commits into
cathugger:masterfrom
teruteru128:filter-long-lines
Open

teruteru128 wants to merge 2 commits into
cathugger:masterfrom
teruteru128:filter-long-lines

Conversation

@teruteru128

Copy link
Copy Markdown

When many patterns are joined into a single alternation, for example
(?:pat1)|(?:pat2)|..., so that DOFILTER performs one pcre2_match()
call per key instead of one per filter, the resulting line easily exceeds
the 128 byte buffer loadfilterfile() read into. My own 522 byte filter
file was cut into five fragments, none of which compiled, leaving zero
filters registered while reporting five confusing "unmatched closing
parenthesis" errors. A plain filter file is worse off still: the
fragments are valid base32, so they are registered as filters that were
never asked for.

The first commit reads each line into a buffer that grows as needed, so a
line of any length ends up as a single filter. The second one strips the
CR of CRLF line endings, which otherwise became part of the filter when a
filter file written on Windows was read elsewhere; a lone CR is left
alone so that it cannot split a filter in two.

Behaviour is otherwise unchanged: empty lines, # and // comments and a
last line without a terminating newline are handled as before.

Tested with lines of 125-3000 characters, lines ending exactly at a buffer
boundary, files with and without a trailing newline, CRLF files, and files
containing NUL bytes (no unbounded buffer growth); built with
-Wall -Wextra -pedantic with no new warnings.

Read filter file lines into a growable buffer instead of a fixed 128
byte one, so that long lines (PCRE2 patterns in particular) are no
longer silently split into several filters.
A filter file written on Windows kept a trailing CR when read on
other platforms, which became part of the filter itself. A lone CR
is still left alone so that it cannot split a filter in two.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant