Skip to content

Commit

Permalink
🚑️ Prevent BFT unaligned compressed data corruption (MarlinFirmware#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
ellensp authored and thinkyhead committed Jun 15, 2021
1 parent dba8773 commit cdd9507
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions Marlin/src/feature/binary_stream.h
Expand Up @@ -24,9 +24,11 @@
#include "../inc/MarlinConfig.h"

#define BINARY_STREAM_COMPRESSION

#if ENABLED(BINARY_STREAM_COMPRESSION)
#include "../libs/heatshrink/heatshrink_decoder.h"
// STM32 (and others?) require a word-aligned buffer for SD card transfers via DMA
static __attribute__((aligned(sizeof(size_t)))) uint8_t decode_buffer[512] = {};
static heatshrink_decoder hsd;
#endif

inline bool bs_serial_data_available(const serial_index_t index) {
Expand All @@ -37,16 +39,6 @@ inline int bs_read_serial(const serial_index_t index) {
return SERIAL_IMPL.read(index);
}

#if ENABLED(BINARY_STREAM_COMPRESSION)
static heatshrink_decoder hsd;
#if BOTH(ARDUINO_ARCH_STM32F1, SDIO_SUPPORT)
// STM32 requires a word-aligned buffer for SD card transfers via DMA
static __attribute__((aligned(sizeof(size_t)))) uint8_t decode_buffer[512] = {};
#else
static uint8_t decode_buffer[512] = {};
#endif
#endif

class SDFileTransferProtocol {
private:
struct Packet {
Expand Down

0 comments on commit cdd9507

Please sign in to comment.