From b8de9285970775d539f09f7bc81d3eae24e410e9 Mon Sep 17 00:00:00 2001 From: TazyFoundSoup Date: Mon, 16 Feb 2026 18:30:44 +1100 Subject: feat(bmp): Implement ff_bmp_isvalid function for BMP signature validation --- src/format/image/bmp.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/format/image/bmp.c (limited to 'src/format/image/bmp.c') diff --git a/src/format/image/bmp.c b/src/format/image/bmp.c new file mode 100644 index 0000000..d947a83 --- /dev/null +++ b/src/format/image/bmp.c @@ -0,0 +1,27 @@ +#include "tinyff/image/bmp.h" +#include "tinyff/dbg.h" +#include "bmp.h" + +ff_result ff_bmp_isvalid(ff_stream* stream) +{ + ff_dprintf("png: validating signature\n"); + + char raw_sig[2]; + if (stream->read(raw_sig, 2, stream->user) != 2) { + ff_dprintf("bmp: failed to read signature bytes\n"); + return FF_RESULT_ERROR_INVALID_FILE; + } + + ff_dprintf( + "bmp: signature read: %02X %02X \n", + raw_sig[0], raw_sig[1] + ); + + if (memcmp(raw_sig, BMP_SIGNATURE, 2) != 0) { + ff_dprintf("bmp: signature mismatch\n"); + return FF_RESULT_ERROR_INVALID_PNG_SIGNITURE; + } + + ff_dprintf("bmp: signature valid\n"); + return FF_RESULT_OK; +} \ No newline at end of file -- cgit v1.2.3