Bug 68236 - searchText(String,PositionInParagraph)@XWPFParagraph can wrongly reset BeginCharPos
Summary: searchText(String,PositionInParagraph)@XWPFParagraph can wrongly reset BeginC...
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 5.3.x-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-27 04:14 UTC by zhonghao
Modified: 2023-11-27 10:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zhonghao 2023-11-27 04:14:49 UTC
The code is as follows:

public TextSegment searchText(String searched, PositionInParagraph startPos) {
  ...
   int beginRunPos = 0, candCharPos = 0;
   for (int runPos = startRun; runPos < rArray.length; runPos++) {
            int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos;
 ....
}

beginTextPos and beginCharPos are in the loop and can be wrongly reset. 

NPOI fixed a similar bug:

https://github.com/nissl-lab/npoi/commit/38cdadd3a67e59e6bede7f77996fbf048c5ffc7e

In NPOI, the fixed code is as follows:

public TextSegment SearchText(String searched, PositionInParagraph startPos){
...
int beginRunPos = 0, beginTextPos = 0, beginCharPos = 0,candCharPos = 0;
    for (int runPos = startRun; runPos < paragraph.GetRList().Count; runPos++){
 int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos = 0;
...
    }
Comment 1 PJ Fanning 2023-11-27 10:32:48 UTC
We are not going to just copy NPOI. Please provide real world examples. POI is a volunteer project and it is normally best to provide a patch with a test case yourself.