diff --git a/ChangeLog b/ChangeLog index 92cbb527..5a653d13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23631,3 +23631,7 @@ * Updated the build package list for Ubuintu 22.04 in 'INSTALL'. 2022-11-07 Fred Gleason * Fixed a regression that broke the 'make deb' target. +2022-11-09 Fred Gleason + * Added a file format check to the 'Image Manager' dialog in + rdadmin(1) to ensure that only JPEG or PNG formatted image files can + be imported. diff --git a/lib/rdconf.cpp b/lib/rdconf.cpp index b17dbc0d..06b498a1 100644 --- a/lib/rdconf.cpp +++ b/lib/rdconf.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include @@ -1122,3 +1124,28 @@ int RDCheckReturnCode(const QString &msg,int code,int ok_value) } return code; } + + +QString RDMimeType(const QString &filename,bool *ok) +{ + QStringList args; + QString ret; + + args.push_back("--mime-type"); + args.push_back(filename); + QProcess *proc=new QProcess(); + proc->start("/usr/bin/file",args); + proc->waitForFinished(); + if((proc->exitStatus()!=QProcess::NormalExit)||(proc->exitCode()!=0)) { + *ok=false; + delete proc; + return ret; + } + *ok=true; + ret=QString(proc->readAllStandardOutput()). + split(":",QString::SkipEmptyParts).last().trimmed(); + + delete proc; + + return ret; +} diff --git a/lib/rdconf.h b/lib/rdconf.h index d8e3aaf4..535487ec 100644 --- a/lib/rdconf.h +++ b/lib/rdconf.h @@ -111,6 +111,7 @@ QList RDGetPids(const QString &program); int RDCheckExitCode(const QString &msg,int exit_code); int RDCheckExitCode(RDConfig *config,const QString &msg,int exit_code); int RDCheckReturnCode(const QString &msg,int code,int ok_value); +QString RDMimeType(const QString &filename,bool *ok); #endif // RDCONF_H diff --git a/lib/rdfeed.cpp b/lib/rdfeed.cpp index cacb57f8..a0a017aa 100644 --- a/lib/rdfeed.cpp +++ b/lib/rdfeed.cpp @@ -713,6 +713,19 @@ int RDFeed::importImageFile(const QString &pathname,QString *err_msg, QSize max=rda->rssSchemas()->maximumImageSize(rssSchema()); *err_msg="OK"; + // + // Check the file type + // + QString mimetype=RDMimeType(pathname,&ok); + if(!ok) { + *err_msg=tr("Error validating image file."); + return -1; + } + if((mimetype!="image/jpeg")&&(mimetype!="image/png")) { + *err_msg=tr("Unsupported image file format."); + return -1; + } + // // Load the image //