Skip to content

Fix ArgumentOutOfRangeException in IrishLowerCaseFilter span slicing, #1150 - #1286

Merged
paulirwin merged 3 commits into
apache:masterfrom
paulirwin:issue/1150
May 1, 2026
Merged

Fix ArgumentOutOfRangeException in IrishLowerCaseFilter span slicing, #1150#1286
paulirwin merged 3 commits into
apache:masterfrom
paulirwin:issue/1150

Conversation

@paulirwin

Copy link
Copy Markdown
Contributor
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Fixes #1150

Description

IrishLowerCaseFilter was incorrectly calculating the span length for the lowercase operation. When the n-/t-prothesis path runs (inserting a hyphen after 'n' or 't'), idx becomes 2 and the span length should be (chLen - idx), not chLen. This caused out-of-bounds span creation.

The fix calculates spanLen = chLen - idx and uses this corrected length for both the source and destination spans, as well as the spare buffer allocation.

Added a regression test using a custom TightBufferTokenStream that writes directly into CharTermAttribute.termBuffer to bypass the Oversize over-allocation all public tokenizer paths use, producing a buffer sized to exactly the post-prothesis term length. This reliably triggers the ArgumentOutOfRangeException on the buggy code.

AI: co-authored with Claude Code Opus 4.7

…pache#1150)

IrishLowerCaseFilter was incorrectly calculating the span length for
the lowercase operation. When the n-/t-prothesis path runs (inserting
a hyphen after 'n' or 't'), idx becomes 2 and the span length should
be (chLen - idx), not chLen. This caused out-of-bounds span creation.

The fix calculates spanLen = chLen - idx and uses this corrected
length for both the source and destination spans, as well as the spare
buffer allocation.

Added a regression test using a custom TightBufferTokenStream that
writes directly into CharTermAttribute.termBuffer to bypass the
Oversize over-allocation all public tokenizer paths use, producing a
buffer sized to exactly the post-prothesis term length. This reliably
triggers the ArgumentOutOfRangeException on the buggy code.

Fixes apache#1150

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@paulirwin paulirwin added the notes:bug-fix Contains a fix for a bug label May 1, 2026
Tests all n-/t- prothesis combinations across plain and accented (fada)
upper vowels to guard against regressions in output correctness.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a span-slicing bug in IrishLowerCaseFilter that could throw ArgumentOutOfRangeException during n-/t-prothesis processing, and adds regression coverage to reliably reproduce the prior failure.

Changes:

  • Correct span length calculation in IrishLowerCaseFilter by using spanLen = chLen - idx for source/destination spans and spare buffer sizing.
  • Add prothesis correctness tests (upper vowels + fadas) for both n- and t- prefixes.
  • Add a regression test using a tight-buffer TokenStream to reproduce the out-of-bounds span creation from issue #1150.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Lucene.Net.Analysis.Common/Analysis/Ga/IrishLowerCaseFilter.cs Fixes span slicing length to avoid out-of-range span creation when idx is advanced during prothesis.
src/Lucene.Net.Tests.Analysis.Common/Analysis/Ga/TestIrishLowerCaseFilter.cs Adds targeted correctness + regression tests, including a tight-buffer stream to trigger the previous failure mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Lucene.Net.Tests.Analysis.Common/Analysis/Ga/TestIrishLowerCaseFilter.cs Outdated
Comment thread src/Lucene.Net.Tests.Analysis.Common/Analysis/Ga/TestIrishLowerCaseFilter.cs Outdated
@paulirwin
paulirwin merged commit be94cfd into apache:master May 1, 2026
214 of 215 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:bug-fix Contains a fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random failing test: TestIrishAnalyzer.TestRandomStrings

2 participants