You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ftplib: parse229 raises ValueError instead of error_proto on malformed non-numeric port in EPSV response #162128
When parsing a malformed 229 Entering Extended Passive Mode response where the port field is non-numeric or empty, ftplib.parse229 raises an unhandled ValueError: invalid literal for int() with base 10 instead of ftplib.error_proto(resp).
Error: <class 'ValueError'> invalid literal for int() with base 10: 'invalid'
Error: <class 'ValueError'> invalid literal for int() with base 10: ''
Expected Behavior:
As stated in the function's docstring (Raises error_proto if it does not contain '(|||port|)'), malformed server responses should raise ftplib.error_proto(resp). This also aligns with parse227, which matches digits with regex and raises error_proto(resp) on malformed responses.
Root Cause:
In Lib/ftplib.py:parse229:
parts=resp[left+1:right].split(resp[left+1])
iflen(parts) !=5:
raiseerror_proto(resp)
host=peer[0]
port=int(parts[3])
returnhost, port
parts[3] is converted directly with int(parts[3]) without verifying that it contains digits or wrapping in try...except ValueError: raise error_proto(resp).
Activity