cook: check output buffer size before decoding