pycom / pycom-libraries

MicroPython libraries and examples that work out of the box on Pycom's IoT modules
334 stars 373 forks source link

OTA.py example: issues when python file contains "\r\n\r\n" #158

Open SebastiaanMerckx opened 3 years ago

SebastiaanMerckx commented 3 years ago

Issue:

I observed while testing OTA upgrade (using lib OTA.py), that the hash for a specific file was always incorrectly calculated by the OTA.py.

In fact, the issue is that the stripping of HTML header in "get_data()" function does not properly work if the "result" contains more than 1 "\r\n\r\n". result = result.decode().split("\r\n\r\n")[1].encode()

To be replaced with something like:

index = result.decode().find("\r\n\r\n")
result = result[index+4:]

This issue can be reproduced by running the OTA server and making sure that a file containing "\r\n\r\n" (2 empty lines on top, or 1 empty line between 2 statements) needs to be downloaded and hash-verified.

SebastiaanMerckx commented 3 years ago

or in 1 line: result = result[result.decode().find("\r\n\r\n")+4:]