util/PdfAdmission.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <QFile> | ||
| 3 | |||
| 4 | namespace PdfAdmission { | ||
| 5 | inline constexpr qint64 maximumBytes = 64 * 1024 * 1024; | ||
| 6 | enum class Result { Accepted, TooLarge, NotPdf, Unreadable }; | ||
| 7 | |||
| 8 | 10 | inline Result checkFile(const QString &path) { | |
| 9 |
1/1✓ Branch 2 → 3 taken 10 times.
|
10 | QFile file(path); |
| 10 |
3/3✓ Branch 4 → 5 taken 10 times.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 9 times.
|
10 | if (!file.open(QIODevice::ReadOnly)) return Result::Unreadable; |
| 11 |
3/3✓ Branch 7 → 8 taken 9 times.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 10 taken 8 times.
|
9 | if (file.size() > maximumBytes) return Result::TooLarge; |
| 12 | // Qt PDF accepts headers after a short binary preamble. Read only this prefix. | ||
| 13 |
3/3✓ Branch 10 → 11 taken 8 times.
✓ Branch 13 → 14 taken 4 times.
✓ Branch 13 → 15 taken 4 times.
|
8 | return file.read(1024).contains("%PDF-") ? Result::Accepted : Result::NotPdf; |
| 14 | 10 | } | |
| 15 | } // namespace PdfAdmission | ||
| 16 |