[
https://issues.apache.org/jira/browse/RAT-589?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Philipp Ottlinger updated RAT-589:
----------------------------------
Description:
Header line limit is dead code — whole files buffered in memory and fed to
quadratic license-matcher regexes
in apache-rat-core/src/main/java/org/apache/rat/analysis/HeaderCheckWorker.java
readHeader() declared headerLinesRead, tested it in the loop condition
(headerLinesRead < numberOfLines), but never incremented it, so the documented
DEFAULT_NUMBER_OF_RETAINED_HEADER_LINES=50 bound was dead code and every
scanned file was buffered in full (twice: raw + pruned copy) and fed to the
SPDX/copyright matcher regexes. The one-line fix (headerLinesRead++ in the loop
body) restores the documented behavior; with the bound live, the downstream
quadratic regex costs (SPDXMatcherFactory GROUP_SELECTOR greedy .* prefix,
CopyrightMatcher find()/start()==0) are capped to 50 lines of input per file.
The bound is already configurable: the HeaderCheckWorker(generatedMatcher,
reader, numberOfRetainedHeaderLine, licenses, document) constructor takes the
line count and the convenience constructor passes the documented default of 50;
no new option plumbing needed.
This issue was found using Claude agents to study the security of open-source
projects (finder)
*Line limit set to 400 lines as default!*
was:
Header line limit is dead code — whole files buffered in memory and fed to
quadratic license-matcher regexes
in apache-rat-core/src/main/java/org/apache/rat/analysis/HeaderCheckWorker.java
readHeader() declared headerLinesRead, tested it in the loop condition
(headerLinesRead < numberOfLines), but never incremented it, so the documented
DEFAULT_NUMBER_OF_RETAINED_HEADER_LINES=50 bound was dead code and every
scanned file was buffered in full (twice: raw + pruned copy) and fed to the
SPDX/copyright matcher regexes. The one-line fix (headerLinesRead++ in the loop
body) restores the documented behavior; with the bound live, the downstream
quadratic regex costs (SPDXMatcherFactory GROUP_SELECTOR greedy .* prefix,
CopyrightMatcher find()/start()==0) are capped to 50 lines of input per file.
The bound is already configurable: the HeaderCheckWorker(generatedMatcher,
reader, numberOfRetainedHeaderLine, licenses, document) constructor takes the
line count and the convenience constructor passes the documented default of 50;
no new option plumbing needed.
This issue was found using Claude agents to study the security of open-source
projects (finder)
> Header line limit is dead code — whole files buffered in memory and fed to
> quadratic license-matcher regexes
> ------------------------------------------------------------------------------------------------------------
>
> Key: RAT-589
> URL: https://issues.apache.org/jira/browse/RAT-589
> Project: Apache RAT
> Issue Type: Bug
> Affects Versions: 0.18
> Reporter: Philipp Ottlinger
> Priority: Major
> Fix For: 0.19
>
>
> Header line limit is dead code — whole files buffered in memory and fed to
> quadratic license-matcher regexes
> in
> apache-rat-core/src/main/java/org/apache/rat/analysis/HeaderCheckWorker.java
> readHeader() declared headerLinesRead, tested it in the loop condition
> (headerLinesRead < numberOfLines), but never incremented it, so the
> documented DEFAULT_NUMBER_OF_RETAINED_HEADER_LINES=50 bound was dead code and
> every scanned file was buffered in full (twice: raw + pruned copy) and fed to
> the SPDX/copyright matcher regexes. The one-line fix (headerLinesRead++ in
> the loop body) restores the documented behavior; with the bound live, the
> downstream quadratic regex costs (SPDXMatcherFactory GROUP_SELECTOR greedy .*
> prefix, CopyrightMatcher find()/start()==0) are capped to 50 lines of input
> per file. The bound is already configurable: the
> HeaderCheckWorker(generatedMatcher, reader, numberOfRetainedHeaderLine,
> licenses, document) constructor takes the line count and the convenience
> constructor passes the documented default of 50; no new option plumbing
> needed.
> This issue was found using Claude agents to study the security of open-source
> projects (finder)
> *Line limit set to 400 lines as default!*
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)