hubitat icon indicating copy to clipboard operation
hubitat copied to clipboard

Fix off-by-one error when checking for last fragment

Open mbbush opened this issue 2 years ago • 0 comments

I discovered this bug when trying to update my inovelli LZW30 switches to firmware 1.22. The firmware updater worked fine for other firmware files, but not this one.

The reason is that there's a bug in the logic for checking for whether this is the last fragment, which falsely sets to true when this is the next-to-last fragment and the actual last fragment will only have 1 byte in it.

This only causes an actual problem when the firmware size is 1 more than a multiple of the fragment size, which is the case with the LZW30 firmware version 1.22 (93601 bytes).

Once I applied this change locally, I was able to successfully update my switches. I successfully flashed multiple firmware files with a variety of sizes, resulting in last-fragment sizes of 40 bytes, 1 byte, and something in between.

For more context, see https://community.inovelli.com/t/unable-to-update-black-switch-firmware-using-hubitat/9413/2

mbbush avatar Oct 27 '21 18:10 mbbush