[fbreader] Prevent a crash in <aside> blocks

This commit is contained in:
Slava Monich 2019-11-28 00:52:04 +02:00
parent 556c3bd351
commit 85a121633b
4 changed files with 55 additions and 30 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2016-2019 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -32,6 +32,8 @@ BookReader::BookReader(BookModel &model) : myModel(model) {
myTextParagraphExists = false;
myContentsParagraphExists = false;
myBookTextParagraphExists = false;
myBookContentsParagraphExists = false;
myInsideTitle = false;
mySectionContainsRegularContents = false;
@ -41,10 +43,20 @@ BookReader::~BookReader() {
}
void BookReader::setMainTextModel() {
myCurrentTextModel = myModel.myBookTextModel;
if (myCurrentTextModel != myModel.myBookTextModel) {
myCurrentTextModel = myModel.myBookTextModel;
myTextParagraphExists = myBookTextParagraphExists;
myContentsParagraphExists = myBookContentsParagraphExists;
}
}
void BookReader::setFootnoteTextModel(const std::string &id) {
if (myCurrentTextModel == myModel.myBookTextModel) {
myBookTextParagraphExists = myTextParagraphExists;
myBookContentsParagraphExists = myContentsParagraphExists;
}
myTextParagraphExists = false;
myContentsParagraphExists = false;
std::map<std::string,shared_ptr<ZLTextModel> >::iterator it = myModel.myFootnotes.find(id);
if (it != myModel.myFootnotes.end()) {
myCurrentTextModel = (*it).second;
@ -54,6 +66,14 @@ void BookReader::setFootnoteTextModel(const std::string &id) {
}
}
void BookReader::setFootnoteTextModel(const std::string &id, const std::string &alt)
{
setFootnoteTextModel(id);
if (!alt.empty() && myModel.myFootnotes.find(alt) == myModel.myFootnotes.end()) {
myModel.myFootnotes.insert(std::make_pair(alt, myCurrentTextModel));
}
}
void BookReader::unsetTextModel() {
myCurrentTextModel = 0;
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016-2019 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,6 +41,7 @@ public:
void setMainTextModel();
void setFootnoteTextModel(const std::string &id);
void setFootnoteTextModel(const std::string &id, const std::string &alt);
void unsetTextModel();
void insertEndOfSectionParagraph();
@ -91,6 +93,8 @@ private:
bool myTextParagraphExists;
bool myContentsParagraphExists;
bool myBookTextParagraphExists;
bool myBookContentsParagraphExists;
std::stack<ZLTextTreeParagraph*> myTOCStack;
bool myLastTOCParagraphIsEmpty;

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2016-2019 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -394,7 +394,7 @@ XHTMLTagFootnoteAction::XHTMLTagFootnoteAction() {
void XHTMLTagFootnoteAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
const char *id = reader.attributeValue(xmlattributes, "id");
if (id) {
bookReader(reader).setFootnoteTextModel(id);
bookReader(reader).setFootnoteTextModel(id, reader.myReferenceName + "#" + id);
}
}

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2016-2019 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,8 +42,8 @@ class XHTMLTagAction {
public:
virtual ~XHTMLTagAction();
virtual void doAtStart(XHTMLReader &reader, const char **xmlattributes);
virtual void doAtEnd(XHTMLReader &reader);
virtual void doAtStart(XHTMLReader &reader, const char **xmlattributes);
virtual void doAtEnd(XHTMLReader &reader);
protected:
static BookReader &bookReader(XHTMLReader &reader);
@ -87,28 +87,28 @@ private:
bool processNamespaces() const;
void haveContent();
void beginParagraph();
void haveContent();
void beginParagraph();
void endParagraph();
void applyStyles(ParseContext &context);
void addStyleParagraph(const ZLTextStyleEntry &style);
void addBottomMargin(short size, ZLTextStyleEntry::SizeUnit unit);
bool elementHasTopMargin(const ParseContext &context) const;
bool elementHasBottomMargin(const ParseContext &context) const;
void applyBottomMargins();
void addPageBreak();
void applyStyles(ParseContext &context);
void addStyleParagraph(const ZLTextStyleEntry &style);
void addBottomMargin(short size, ZLTextStyleEntry::SizeUnit unit);
bool elementHasTopMargin(const ParseContext &context) const;
bool elementHasBottomMargin(const ParseContext &context) const;
void applyBottomMargins();
void addPageBreak();
private:
BookReader &myModelReader;
std::string myPathPrefix;
std::string myReferenceName;
std::string myReferenceDirName;
int myPreformatted;
int myPreformatted;
StyleSheetTable myStyleSheetTable;
StyleSheetTable::ElementList myElementStack;
StyleSheetTable::StyleList myStyleStack;
std::vector<ParseContext> myParseStack;
std::vector<ZLTextStyleEntry> myBottomMargins;
StyleSheetTable::ElementList myElementStack;
StyleSheetTable::StyleList myStyleStack;
std::vector<ParseContext> myParseStack;
std::vector<ZLTextStyleEntry> myBottomMargins;
StyleSheetSingleStyleParser myStyleParser;
shared_ptr<StyleSheetTableParser> myTableParser;
enum {
@ -118,14 +118,15 @@ private:
} myReadState;
friend class XHTMLTagAction;
friend class XHTMLTagStyleAction;
friend class XHTMLTagLinkAction;
friend class XHTMLTagHyperlinkAction;
friend class XHTMLTagPreAction;
friend class XHTMLTagControlAction;
friend class XHTMLTagParagraphWithControlAction;
friend class XHTMLTagBodyAction;
friend class XHTMLTagImageAction;
friend class XHTMLTagStyleAction;
friend class XHTMLTagLinkAction;
friend class XHTMLTagHyperlinkAction;
friend class XHTMLTagPreAction;
friend class XHTMLTagControlAction;
friend class XHTMLTagParagraphWithControlAction;
friend class XHTMLTagBodyAction;
friend class XHTMLTagImageAction;
friend class XHTMLTagFootnoteAction;
};
#endif /* __XHTMLREADER_H__ */