mirror of
https://github.com/hyprwm/hyprgraphics.git
synced 2026-05-08 10:08:01 +02:00
formats: check magic bytes for jpeg and webp
This commit is contained in:
parent
45dcdd67d2
commit
fc22c66103
3 changed files with 7 additions and 1 deletions
|
|
@ -74,7 +74,7 @@ Hyprgraphics::CImage::CImage(const std::string& path) : filepath(path) {
|
|||
if (first_word == "PNG") {
|
||||
CAIROSURFACE = PNG::createSurfaceFromPNG(path);
|
||||
mime = "image/png";
|
||||
} else if (first_word == "JPEG" && !type_str.contains("XL") && !type_str.contains("2000") {
|
||||
} else if (first_word == "JPEG" && !type_str.contains("XL") && !type_str.contains("2000")) {
|
||||
CAIROSURFACE = JPEG::createSurfaceFromJPEG(path);
|
||||
imageHasAlpha = false;
|
||||
mime = "image/jpeg";
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ std::expected<cairo_surface_t*, std::string> JPEG::createSurfaceFromJPEG(const s
|
|||
file.seekg(0);
|
||||
file.read(reinterpret_cast<char*>(bytes.data()), bytes.size());
|
||||
|
||||
if (bytes[0] != 0xFF || bytes[1] != 0xD8)
|
||||
return std::unexpected("loading jpeg: invalid magic bytes");
|
||||
|
||||
// now the JPEG is in the memory
|
||||
|
||||
jpeg_decompress_struct decompressStruct = {};
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ std::expected<cairo_surface_t*, std::string> WEBP::createSurfaceFromWEBP(const s
|
|||
file.seekg(0);
|
||||
file.read(reinterpret_cast<char*>(bytes.data()), bytes.size());
|
||||
|
||||
if (bytes[0] != 'R' || bytes[1] != 'I' || bytes[2] != 'F' || bytes[3] != 'F')
|
||||
return std::unexpected("loading webp: invalid magic bytes");
|
||||
|
||||
// now the WebP is in the memory
|
||||
|
||||
WebPDecoderConfig config;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue