[1.7.x] Fixed #23638 -- Prevented crash while parsing invalid cookie content

Thanks Philip Gatt for the report and Tim Graham for the review.
Backport of 59d487e7fc from master.