Check buffer length more strictly.

MFC after:	1 day