Random DVI cleanups

at least certain documents triggers asserts in qt debug mode if a
filename does not contain a space.

Malformed TFM font files can trigger quite serious out of bounds writes.

Also simplify initializations
This commit is contained in:
Sune Vuorela 2024-06-10 16:32:34 +02:00 committed by Albert Astals Cid
parent 0bae96a5c0
commit 85e8b47a89
4 changed files with 10 additions and 27 deletions

View File

@ -14,6 +14,7 @@
#include <QDataStream>
#include <QFile>
#include <QLoggingCategory>
#include <array>
//#define DEBUG_TFM
@ -38,7 +39,7 @@ TeXFont_TFM::TeXFont_TFM(TeXFontDefinition *parent)
#ifdef DEBUG_TFM
qCDebug(OkularDviDebug) << "lf= " << lf << "lh= " << lh << "\nbc= " << bc << "\nec= " << ec << "\nnw= " << nw << "\nnh= " << nh << "\nnd= " << nd;
#endif
if ((bc > ec) || (ec >= TeXFontDefinition::max_num_of_chars_in_font)) {
if ((bc > ec) || (ec >= TeXFontDefinition::max_num_of_chars_in_font) || (nw >= TeXFontDefinition::max_num_of_chars_in_font) || (nh >= 16)) {
qCCritical(OkularDviDebug) << "TeXFont_TFM::TeXFont_TFM( filename=" << parent->filename << " ): The font has an invalid bc and ec entries.";
file.close();
return;
@ -53,10 +54,7 @@ TeXFont_TFM::TeXFont_TFM(TeXFontDefinition *parent)
#endif
// Width table
fix_word widthTable_in_units_of_design_size[TeXFontDefinition::max_num_of_chars_in_font];
for (fix_word &fw : widthTable_in_units_of_design_size) {
fw.value = 0;
}
std::array<fix_word, TeXFontDefinition::max_num_of_chars_in_font> widthTable_in_units_of_design_size = {};
file.seek(24 + 4 * lh + 4 * (ec - bc));
for (unsigned int i = 0; i < nw; i++) {
@ -72,10 +70,7 @@ TeXFont_TFM::TeXFont_TFM(TeXFontDefinition *parent)
}
// Height table
fix_word heightTable_in_units_of_design_size[16];
for (fix_word &fw : heightTable_in_units_of_design_size) {
fw.value = 0;
}
std::array<fix_word, 16> heightTable_in_units_of_design_size = {};
for (unsigned int i = 0; i < nh; i++) {
stream >> heightTable_in_units_of_design_size[i].value;
}

View File

@ -27,7 +27,7 @@ public:
return (double(value)) / (double(1 << 20));
}
qint32 value;
qint32 value = 0;
};
class TeXFont_TFM : public TeXFont

View File

@ -49,15 +49,11 @@ void dviRenderer::prescan_embedPS(char *cp, quint8 *beginningOfSpecialCommand)
QString command = QString::fromLocal8Bit(cp + 7);
QString include_command = command.simplified();
QString include_command = command.trimmed();
// The line is supposed to start with "..ile=", and then comes the
// filename. Figure out what the filename is and stow it away. Of
// course, this does not work if the filename contains spaces
// (already the simplified() above is wrong). If you have
// files like this, go away.
QString EPSfilename = include_command;
EPSfilename.truncate(EPSfilename.indexOf(QLatin1Char(' ')));
// Strip enclosing quotation marks which are included by some LaTeX
// macro packages (but not by others). This probably means that
@ -420,15 +416,11 @@ void dviRenderer::prescan_ParsePSFileSpecial(const QString &cp)
qCDebug(OkularDviDebug) << "epsf-special: psfile=" << cp;
#endif
QString include_command = cp.simplified();
QString include_command = cp.trimmed();
// The line is supposed to start with "..ile=", and then comes the
// filename. Figure out what the filename is and stow it away. Of
// course, this does not work if the filename contains spaces
// (already the simplified() above is wrong). If you have
// files like this, go away.
// filename. Figure out what the filename is and stow it away.
QString EPSfilename = include_command;
EPSfilename.truncate(EPSfilename.indexOf(QLatin1Char(' ')));
// Strip enclosing quotation marks which are included by some LaTeX
// macro packages (but not by others). This probably means that

View File

@ -329,15 +329,11 @@ void dviRenderer::epsf_special(const QString &cp)
qCDebug(OkularDviDebug) << "epsf-special: psfile=" << cp;
#endif
QString include_command = cp.simplified();
QString include_command = cp.trimmed();
// The line is supposed to start with "..ile=", and then comes the
// filename. Figure out what the filename is and stow it away. Of
// course, this does not work if the filename contains spaces
// (already the simplified() above is wrong). If you have
// files like this, go away.
// filename. Figure out what the filename is and stow it away.
QString EPSfilename_orig = include_command;
EPSfilename_orig.truncate(EPSfilename_orig.indexOf(QLatin1Char(' ')));
// Strip enclosing quotation marks which are included by some LaTeX
// macro packages (but not by others). This probably means that