Fix ArgumentOutOfRangeException in IrishLowerCaseFilter span slicing, #1150 - #1286
Merged
Conversation
…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>
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>
Contributor
There was a problem hiding this comment.
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
IrishLowerCaseFilterby usingspanLen = chLen - idxfor source/destination spans and spare buffer sizing. - Add prothesis correctness tests (upper vowels + fadas) for both
n-andt-prefixes. - Add a regression test using a tight-buffer
TokenStreamto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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