+ cur_size = bytestream2_get_be32(gb);
+ cursor_w = bytestream2_get_byte(gb);
+ cursor_h = bytestream2_get_byte(gb);
+ cursor_hot_x = bytestream2_get_byte(gb);
+ cursor_hot_y = bytestream2_get_byte(gb);
+ cursor_fmt = bytestream2_get_byte(gb);
+
+ cursor_stride = cursor_w * 4;
+
+ if (cursor_w < 1 || cursor_w > 256 ||
+ cursor_h < 1 || cursor_h > 256) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid cursor dimensions %dx%d\n",
+ cursor_w, cursor_h);
+ return AVERROR_INVALIDDATA;
+ }
+ if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
+ av_log(avctx, AV_LOG_WARNING, "Invalid hotspot position %d,%d\n",
+ cursor_hot_x, cursor_hot_y);
+ cursor_hot_x = FFMIN(cursor_hot_x, cursor_w - 1);
+ cursor_hot_y = FFMIN(cursor_hot_y, cursor_h - 1);
+ }
+ if (cur_size - 9 > bytestream2_get_bytes_left(gb) ||
+ c->cursor_w * c->cursor_h / 4 > cur_size) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %d/%d\n",
+ cur_size, bytestream2_get_bytes_left(gb));
+ return AVERROR_INVALIDDATA;
+ }
+ if (cursor_fmt != 1 && cursor_fmt != 32) {
+ avpriv_report_missing_feature(avctx, "Cursor format %d",
+ cursor_fmt);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ if (cursor_fmt == 1 && cursor_w % 32) {
+ avpriv_report_missing_feature(avctx, "odd monochrome cursor width %d", cursor_w);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ tmp = av_realloc(c->cursor, cursor_stride * cursor_h);
+ if (!tmp) {
+ av_log(avctx, AV_LOG_ERROR, "Cannot allocate cursor buffer\n");