Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/webp.imageio/webpinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ OIIO_PLUGIN_NAMESPACE_BEGIN
namespace webp_pvt {


// Layout of the start of any webp file
struct WebpHead {
char RIFF[4]; // should contain "RIFF"
uint32_t file_size;
char WEBP[4]; // should contain "WEBP"
};



static bool
webp_exif_payload_has_tiff_header(cspan<uint8_t> exif)
{
Expand Down Expand Up @@ -99,9 +108,12 @@ WebpInput::valid_file(Filesystem::IOProxy* ioproxy) const
if (!ioproxy || ioproxy->mode() != Filesystem::IOProxy::Mode::Read)
return false;

uint8_t header[64] {};
const size_t numRead = ioproxy->pread(header, sizeof(header), 0);
return WebPGetInfo(header, numRead, nullptr, nullptr);
WebpHead head;
return ioproxy->pread(&head, sizeof(head), 0) == sizeof(head)
&& head.RIFF[0] == 'R' && head.RIFF[1] == 'I' //
&& head.RIFF[2] == 'F' && head.RIFF[3] == 'F' //
&& head.WEBP[0] == 'W' && head.WEBP[1] == 'E' //
&& head.WEBP[2] == 'B' && head.WEBP[3] == 'P';
}


Expand Down
Loading