Fix regression introduced with commit d88df4b Revert the commit and use a different approach. Found by OSS-Fuzz.