check len before memcpying into it

valgrind + bff on sf_3e0068c9b19bb548826bed0599f65745-CrdWMI-minimized.gif

Change-Id: I74cc21609f1c97a27e13615593f678cbbc8463e3
(cherry picked from commit d4e64d030092984077021a9af9d281cd64c476bf)
Reviewed-on: https://gerrit.libreoffice.org/10991
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>