egl: check for buffer overflow *before* corrupting our memory