From 98423fa79daf3160946deec8afb597094e2f7876 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 16 Aug 2015 14:00:35 +0300 Subject: [PATCH] Fix FS size and add type size checks --- cores/esp8266/spiffs_api.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index c482c8438..6f63c59cd 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -23,9 +23,12 @@ */ #include "FS.h" +#undef max +#undef min #include "FSImpl.h" #include "spiffs/spiffs.h" #include "debug.h" +#include extern "C" { #include "c_types.h" @@ -119,6 +122,27 @@ protected: config.log_block_size = _blockSize; config.log_page_size = _pageSize; + + if (((uint32_t) std::numeric_limits::max()) < (_size / _blockSize)) { + DEBUGV("spiffs_block_ix type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (_size / _pageSize)) { + DEBUGV("spiffs_page_ix type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (2 + (_size / (2*_pageSize))*2)) { + DEBUGV("spiffs_obj_id type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (_size / _pageSize - 1)) { + DEBUGV("spiffs_span_ix type too small"); + abort(); + } + // hack: even though fs is not initialized at this point, // SPIFFS_buffer_bytes_for_cache uses only fs->config.log_page_size // suggestion: change SPIFFS_buffer_bytes_for_cache to take @@ -381,8 +405,8 @@ extern "C" uint32_t _SPIFFS_page; extern "C" uint32_t _SPIFFS_block; static SPIFFSImpl s_defaultFs( - (uint32_t) &_SPIFFS_start - 0x40200000, - (uint32_t) (&_SPIFFS_end - &_SPIFFS_start), + (uint32_t) (&_SPIFFS_start) - 0x40200000, + (uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start), (uint32_t) &_SPIFFS_page, (uint32_t) &_SPIFFS_block, 5);