micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.38k stars 7.76k forks source link

overFlow ure: Regex Wdt reset when string to parse exceeds 258 characters #3321

Closed DomCharn closed 7 years ago

DomCharn commented 7 years ago

Hi, some context details: micropython 1.9.2 (official) on esp8266 logged elements:

>>> import ure
>>> Match1='200 OK\r\n'
>>> Match2='{?????{!!!}}'
>>> Rcv=Match1+(250-len(Match1)-len(Match2))*'.'+Match2  # String to match length sets to250 bytes
>>> ure.search('200 OK[^{]+({.*})',Rcv).group(1) # match first 200 OK then find something between {} 
'{?????{!!!}}'   # Find of Match2 Confirmed

>>> Rcv=Match1+(257-len(Match1)-len(Match2))*'.'+Match2  # try with string lenth of 257
>>> ure.search('200 OK[^{]+({.*})',Rcv).group(1)
'{?????{!!!}}'  # Still OK 
# 
>>> Rcv=Match1+(258-len(Match1)-len(Match2))*'.'+Match2
>>> ure.search('200 OK[^{]+({.*})',Rcv).group(1)
'{?????{!!!}}'  # Still OK for 258 

>>> Rcv=Match1+(259-len(Match1)-len(Match2))*'.'+Match2
>>> ure.search('200 OK[^{]+({.*})',Rcv).group(1)
'{?????{!!!}}' # We get the right result but no more REPL  prompt . From 259 and above
>>>
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset   # WDT reset 
load 0x40100000, len 31220, room 16
tail 4
chksum 0xf1
load 0x3ffe8000, len 1088, room 4
tail 12
chksum 0x53
ho 0 tail 12 room 4
load 0x3ffe8440, len 3248, room 12
tail 4
chksum 0x56
csum 0x56
l▒▒|▒▒{oc▒▒

The scenario is sytematic, whatever is the Ram size available ( I mean with previously bufferbytes allocated at different and acceptable sizes. On other different esp units same occurrence. Bypass by searching first match(Match1) then new search for Match2 Not insurmountable at all, but trapping the occurrence and so avoiding wdt reboot will be a improvement . Best regards DC

(edited by dpgeorge to improve formatting)

pfalcon commented 7 years ago

Why duplicate reports? Please close the irrelevant one. Also, please consider using more descriptive title.

dpgeorge commented 7 years ago

I can confirm the bug, and it's a duplicate of #2451