diff --git a/esphome/components/esphome/ota/ota_esphome_inflate.c b/esphome/components/esphome/ota/ota_esphome_inflate.c index f69c0cdc4c..f51729f867 100644 --- a/esphome/components/esphome/ota/ota_esphome_inflate.c +++ b/esphome/components/esphome/ota/ota_esphome_inflate.c @@ -195,7 +195,7 @@ static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) { } while (cur >= 0); sum += cur; - if (sum < 0 || sum >= TINF_ARRAY_SIZE(t->trans)) { + if (sum < 0 || sum >= t->size) { return TINF_DATA_ERROR; } @@ -433,6 +433,10 @@ void ota_inflate_init(TINF_DATA *d, unsigned char *dict, unsigned int dict_len) d->dict_ring = dict; d->dict_idx = 0; d->curlen = 0; + d->ltree.trans = d->ltrans; + d->ltree.size = TINF_ARRAY_SIZE(d->ltrans); + d->dtree.trans = d->dtrans; + d->dtree.size = TINF_ARRAY_SIZE(d->dtrans); } /* inflate next output bytes from compressed stream */ diff --git a/esphome/components/esphome/ota/ota_esphome_inflate.h b/esphome/components/esphome/ota/ota_esphome_inflate.h index ebceef357f..15307b5b1f 100644 --- a/esphome/components/esphome/ota/ota_esphome_inflate.h +++ b/esphome/components/esphome/ota/ota_esphome_inflate.h @@ -19,8 +19,9 @@ enum OtaInflateResult { }; struct OtaInflateTree { - uint16_t table[16]; /* table of code length counts */ - uint16_t trans[288]; /* code -> symbol translation table */ + uint16_t table[16]; /* table of code length counts */ + uint16_t *trans; /* code -> symbol translation table, size entries */ + uint16_t size; }; struct OtaInflateState { @@ -51,6 +52,8 @@ struct OtaInflateState { struct OtaInflateTree ltree; /* dynamic length/symbol tree */ struct OtaInflateTree dtree; /* dynamic distance tree */ + uint16_t ltrans[288]; + uint16_t dtrans[32]; /* the distance alphabet has 30 symbols, so the tree is kept small */ }; /* dict must be at least as large as the window the encoder used (its max back reference distance) */