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 --- include/tinyff/image/bmp.h | 4 ++++ src/format/image/bmp.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/format/image/bmp.c diff --git a/include/tinyff/image/bmp.h b/include/tinyff/image/bmp.h index 82edff3..8c4fd56 100644 --- a/include/tinyff/image/bmp.h +++ b/include/tinyff/image/bmp.h @@ -36,4 +36,8 @@ typedef struct { } ff_bmp_ctx; +ff_result ff_bmp_isvalid(ff_stream *stream); +ff_result ff_open_bmp(ff_stream *stream, ff_bmp_ctx **out_ctx); + + #endif BMP_H_ \ No newline at end of file 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