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