Fix infinite loop

  * When actual length is shorter than expected one.

Signed-off-by: Kohei Takahashi <flast@flast.jp>