check input validity, this prevents a few variables from reachin odd values which might have lead to out of array writes and thus might have been exploitable

Originally committed as revision 8522 to svn://svn.ffmpeg.org/ffmpeg/trunk
