1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 17:59:33 +02:00

fixed possible seg.fault

This commit is contained in:
Nikolay Pultsin 2015-09-02 03:09:52 +01:00
parent 7793ba028a
commit bc3e7c932c
2 changed files with 45 additions and 43 deletions

View file

@ -858,13 +858,12 @@ void OleMainStream::getStyleInfo(unsigned int papxOffset, const char *grpprlBuff
}
void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*styleId*/, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo) {
unsigned int sprm = 0; //single propery modifier
unsigned int offset = 0;
while (bytes >= offset + 2) {
switch (OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset)) {
case 0x0835: //bold
sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2);
switch (sprm) {
if (bytes >= offset + 3) {
switch (OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2)) {
case UNSET:
charInfo.FontStyle &= ~CharInfo::FONT_BOLD;
break;
@ -879,10 +878,11 @@ void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*styleId*
default:
break;
}
}
break;
case 0x0836: //italic
sprm = OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2);
switch (sprm) {
if (bytes >= offset + 3) {
switch (OleUtil::getU1Byte(grpprlBuffer, chpxOffset + offset + 2)) {
case UNSET:
charInfo.FontStyle &= ~CharInfo::FONT_ITALIC;
break;
@ -897,16 +897,18 @@ void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*styleId*
default:
break;
}
}
break;
case 0x4a43: //size of font
if (bytes >= offset + 4) {
charInfo.FontSize = OleUtil::getU2Bytes(grpprlBuffer, chpxOffset + offset + 2);
}
break;
default:
break;
}
offset += getPrlLength(grpprlBuffer, chpxOffset + offset);
}
}
void OleMainStream::getSectionInfo(const char *grpprlBuffer, std::size_t bytes, SectionInfo &sectionInfo) {
@ -1058,7 +1060,7 @@ unsigned int OleMainStream::calcCountOfPLC(unsigned int totalSize, unsigned int
unsigned int OleMainStream::getPrlLength(const char *grpprlBuffer, unsigned int byteNumber) {
unsigned int tmp;
unsigned int opCode = OleUtil::getU2Bytes(grpprlBuffer, byteNumber);
switch (opCode & 0xe000) {
switch (opCode & 0xE000) {
case 0x0000:
case 0x2000:
return 3;
@ -1073,7 +1075,7 @@ unsigned int OleMainStream::getPrlLength(const char *grpprlBuffer, unsigned int
case 0xC000:
//counting of info length
tmp = OleUtil::getU1Byte(grpprlBuffer, byteNumber + 2);
if (opCode == 0xc615 && tmp == 255) {
if (opCode == 0xC615 && tmp == 255) {
unsigned int del = OleUtil::getU1Byte(grpprlBuffer, byteNumber + 3);
unsigned int add = OleUtil::getU1Byte(grpprlBuffer, byteNumber + 4 + del * 4);
tmp = 2 + del * 4 + add * 3;