44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#ifndef PDFENGINE_HARDENED_LIMITS_H
|
|
#define PDFENGINE_HARDENED_LIMITS_H
|
|
|
|
#include <cstdint>
|
|
|
|
namespace pdfengine::limits {
|
|
|
|
inline constexpr std::uint64_t kMaxDocumentBytes = 1ull << 30;
|
|
|
|
inline constexpr double kMaxPageDimensionPt = 200'000.0;
|
|
|
|
inline constexpr int kMaxPageCount = 100'000;
|
|
|
|
inline constexpr int kMaxObjects = 5'000'000;
|
|
|
|
inline constexpr std::int64_t kMaxRasterPixels = 256ll * 1024 * 1024;
|
|
|
|
inline constexpr bool pageDimensionsOk(double widthPt, double heightPt) noexcept {
|
|
return widthPt > 0.0 && heightPt > 0.0 && widthPt <= kMaxPageDimensionPt &&
|
|
heightPt <= kMaxPageDimensionPt;
|
|
}
|
|
|
|
inline constexpr bool rasterSizeOk(std::int64_t widthPx, std::int64_t heightPx) noexcept {
|
|
if (widthPx <= 0 || heightPx <= 0) return false;
|
|
if (widthPx > kMaxRasterPixels || heightPx > kMaxRasterPixels) return false;
|
|
return widthPx * heightPx <= kMaxRasterPixels;
|
|
}
|
|
|
|
inline constexpr bool documentSizeOk(std::uint64_t bytes) noexcept {
|
|
return bytes > 0 && bytes <= kMaxDocumentBytes;
|
|
}
|
|
|
|
inline constexpr bool pageCountOk(int pages) noexcept {
|
|
return pages >= 0 && pages <= kMaxPageCount;
|
|
}
|
|
|
|
inline constexpr bool objectCountOk(int objects) noexcept {
|
|
return objects >= 0 && objects <= kMaxObjects;
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|