mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
fixed possible OOB exception
This commit is contained in:
parent
cf97d1e51f
commit
11d0004f3f
7 changed files with 27 additions and 17 deletions
|
@ -4,6 +4,7 @@
|
|||
* Fixed NPE in FontEntry.equals()
|
||||
* Fixed NPE in ZLTextPlainModel.getTextLength()
|
||||
* Fixed skip operation on non-compressed zips
|
||||
* Fixed possible AOOB in text model
|
||||
|
||||
===== 1.10.0.3 (Apr 21, 2014) =====
|
||||
* Fixed duplicate processing for some CSS properties
|
||||
|
|
|
@ -44,6 +44,9 @@ abstract class CachedCharStorageBase implements CharStorage {
|
|||
}
|
||||
|
||||
public char[] block(int index) {
|
||||
if (index < 0 && index >= myArray.size()) {
|
||||
return null;
|
||||
}
|
||||
char[] block = myArray.get(index).get();
|
||||
if (block == null) {
|
||||
try {
|
||||
|
|
|
@ -34,6 +34,9 @@ final class SimpleCharStorage implements CharStorage {
|
|||
}
|
||||
|
||||
public char[] block(int index) {
|
||||
if (index < 0 || index >= myArray.size()) {
|
||||
return null;
|
||||
}
|
||||
return myArray.get(index);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,8 +53,7 @@ public interface ZLTextParagraph {
|
|||
|
||||
short getFixedHSpaceLength();
|
||||
|
||||
boolean hasNext();
|
||||
void next();
|
||||
boolean next();
|
||||
}
|
||||
|
||||
public EntryIterator iterator();
|
||||
|
|
|
@ -77,9 +77,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
private short myFixedHSpaceLength;
|
||||
|
||||
EntryIteratorImpl(int index) {
|
||||
myLength = myParagraphLengths[index];
|
||||
myDataIndex = myStartEntryIndices[index];
|
||||
myDataOffset = myStartEntryOffsets[index];
|
||||
reset(index);
|
||||
}
|
||||
|
||||
void reset(int index) {
|
||||
|
@ -132,20 +130,29 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
return myFixedHSpaceLength;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return myCounter < myLength;
|
||||
public boolean next() {
|
||||
if (myCounter >= myLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void next() {
|
||||
int dataOffset = myDataOffset;
|
||||
char[] data = myStorage.block(myDataIndex);
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
if (dataOffset >= data.length) {
|
||||
data = myStorage.block(++myDataIndex);
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
dataOffset = 0;
|
||||
}
|
||||
byte type = (byte)data[dataOffset];
|
||||
if (type == 0) {
|
||||
data = myStorage.block(++myDataIndex);
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
dataOffset = 0;
|
||||
type = (byte)data[0];
|
||||
}
|
||||
|
@ -252,6 +259,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
}
|
||||
++myCounter;
|
||||
myDataOffset = dataOffset;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,8 +349,7 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
|||
final EntryIteratorImpl it = new EntryIteratorImpl(index);
|
||||
while (true) {
|
||||
int offset = 0;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
while (it.next()) {
|
||||
if (it.getType() == ZLTextParagraph.Entry.TEXT) {
|
||||
char[] textData = it.getTextData();
|
||||
int textOffset = it.getTextOffset();
|
||||
|
|
|
@ -59,8 +59,7 @@ public final class ZLTextParagraphCursor {
|
|||
ZLTextHyperlink hyperlink = null;
|
||||
|
||||
final ArrayList<ZLTextElement> elements = myElements;
|
||||
for (ZLTextParagraph.EntryIterator it = myParagraph.iterator(); it.hasNext(); ) {
|
||||
it.next();
|
||||
for (ZLTextParagraph.EntryIterator it = myParagraph.iterator(); it.next(); ) {
|
||||
switch (it.getType()) {
|
||||
case ZLTextParagraph.Entry.TEXT:
|
||||
processTextEntry(it.getTextData(), it.getTextOffset(), it.getTextLength(), hyperlink);
|
||||
|
|
|
@ -682,10 +682,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
}
|
||||
while (paragraph < myModel.getParagraphsNumber()
|
||||
&& myLettersBufferLength < myLettersBuffer.length) {
|
||||
ZLTextParagraph.EntryIterator it = myModel.getParagraph(paragraph++).iterator();
|
||||
while (it.hasNext()
|
||||
&& myLettersBufferLength < myLettersBuffer.length) {
|
||||
it.next();
|
||||
final ZLTextParagraph.EntryIterator it = myModel.getParagraph(paragraph++).iterator();
|
||||
while (myLettersBufferLength < myLettersBuffer.length && it.next()) {
|
||||
if (it.getType() == ZLTextParagraph.Entry.TEXT) {
|
||||
final int len = Math.min(it.getTextLength(),
|
||||
myLettersBuffer.length - myLettersBufferLength);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue