Commit 00cda753 authored by Leslie Zhai's avatar Leslie Zhai

Workaround for parsing mkisofs progress when perStr is not digit

BUG: 384750
parent b1012957
......@@ -130,27 +130,37 @@ void K3b::MkisofsHandler::parseMkisofsOutput( const QString& line )
}
int K3b::MkisofsHandler::parseMkisofsProgress( const QString& line )
int K3b::MkisofsHandler::parseMkisofsProgress(const QString& line)
{
//
// in multisession mode mkisofs' progress does not start at 0 but at (X+Y)/X
// where X is the data already on the cd and Y the data to create
// This is not very dramatic but kind or ugly.
// We just save the first emitted progress value and to some math ;)
//
QString perStr = line;
perStr.truncate( perStr.indexOf('%') );
perStr.truncate(perStr.indexOf('%'));
// FIXME: how to support Inuit or Samaritan Aramaic format or cover all
// formats? right now it only support, for example: 0.52 and 0,52
QRegExp rx("(\\d+.|,+\\d)");
QStringList list;
int pos = 0;
bool ok;
double p = perStr.toDouble( &ok );
if( !ok ) {
while ((pos = rx.indexIn(perStr, pos)) != -1) {
list << rx.cap(1);
pos += rx.matchedLength();
}
if (list.size() < 2)
return -1;
// FIXME: the same story
double p = (list[0].replace(',', '.') + list[1]).toDouble(&ok);
if (!ok) {
qDebug() << "(K3b::MkisofsHandler) Parsing did not work for " << perStr;
return -1;
}
else {
if( d->firstProgressValue < 0 )
} else {
if (d->firstProgressValue < 0)
d->firstProgressValue = p;
return( (int)::ceil( (p - d->firstProgressValue)*100.0/(100.0 - d->firstProgressValue) ) );
return((int)::ceil((p - d->firstProgressValue) * 100.0 /
(100.0 - d->firstProgressValue)));
}
}
......@@ -26,5 +26,22 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
// QTBUG-57553
qDebug() << "DEBUG:" << __PRETTY_FUNCTION__
<< QFile::encodeName(QString::fromRawData((const QChar *)Data, Size));
// PR384750
QStringList lines("xorriso : UPDATE : 0,52\% done, estimate finish Mon Sep 25 11:04:34 2017");
lines << "xorriso : UPDATE : 0.52\% done, estimate finish Mon Sep 25 11:04:34 2017";
lines << "0.52\% done, estimate finish Mon Sep 25 11:04:34 2017";
for (QString line : lines) {
QString perStr = line;
perStr.truncate(perStr.indexOf('%'));
QRegExp rx("(\\d+.|,+\\d)");
QStringList list;
int pos = 0;
while ((pos = rx.indexIn(perStr, pos)) != -1) {
list << rx.cap(1);
pos += rx.matchedLength();
}
if (list.size() > 1)
qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << list[0].replace(',', '.') + list[1];
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment