The input html could be restricted to be less than 256K but it has nothing to do with the memory problem. The message for this checking of course should not use "NO_ENOUGH_MEMOEY".

Btw, the memory checking code with hasEnoughMemory() is at the start before any validation starts. Curious why would it be too late in the flow?