[x265/f40] Backport a fix for crashes when encoding with variable length SEI