Skip to content

Commit

Permalink
Do not make disk images executable
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd committed Aug 28, 2023
1 parent 0bf0622 commit 45fe33c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ bool Executable::isExecutable(const QString& path) {

bool Executable::hasShebang(const QString& path) {
QFile file(path);
qDebug() << "Checking file:" << path;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Failed to open file:" << path;
return false;
}

QTextStream in(&file);
QString firstLine = in.readLine();
file.close();

return firstLine.startsWith("#!");
// Check if the file starts with the shebang sequence
QByteArray firstTwoBytes = file.read(2);
qDebug() << "First two bytes:" << firstTwoBytes;
if (firstTwoBytes == "#!") {
qDebug() << "File has a shebang.";
// Exception: If the MIME type is e.g., "application/x-raw-disk-image",
// then we ignore the shebang
if (QMimeDatabase().mimeTypeForFile(path).name().contains("disk-image")) {
qDebug() << "File is a disk image, so we ignore the shebang.";
return false;
}
return true;
} else {
qDebug() << "File does not have a shebang.";
return false;
}
}

bool Executable::isElf(const QString& path) {
Expand Down

0 comments on commit 45fe33c

Please sign in to comment.