| @@ -47,16 +47,18 @@ static int cdxl_read_probe(const AVProbeData *p) · 46 unmodified lines |
| 47 | if (p->buf_size < CDXL_HEADER_SIZE) | 47 | if (p->buf_size < CDXL_HEADER_SIZE) |
| 48 | return 0; | 48 | return 0; |
| 49 | | 49 | |
| 50 | /* reserved bytes should always be set to 0 */ | 50 | /* check type */ |
| 51 | if (AV_RN64(&p->buf[24]) || AV_RN16(&p->buf[10])) | 51 | if (p->buf[0] > 1) |
| 52 | return 0; | 52 | return 0; |
| 53 | | 53 | |
| 54 | /* check type */ | 54 | /* reserved bytes should always be set to 0 */ |
| 55 | if (p->buf[0] != 1) | 55 | if (p->buf[0] == 1 && (AV_RN64(&p->buf[24]) || AV_RN16(&p->buf[10]))) |
| 56 | return 0; | 56 | return 0; |
| 57 | | 57 | |
| 58 | /* check palette size */ | 58 | /* check palette size */ |
| 59 | if (AV_RB16(&p->buf[20]) > 512) | 59 | if (p->buf[0] == 1 && AV_RB16(&p->buf[20]) > 512) |
| | 60 | return 0; |
| | 61 | if (p->buf[0] == 0 && AV_RB16(&p->buf[20]) > 768) |
| 60 | return 0; | 62 | return 0; |
| 61 | | 63 | |
| 62 | /* check number of planes */ | 64 | /* check number of planes */ |
| @@ -111,7 +113,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 48 unmodified lines |
| 111 | uint32_t current_size, video_size, image_size; | 113 | uint32_t current_size, video_size, image_size; |
| 112 | uint16_t audio_size, palette_size, width, height; | 114 | uint16_t audio_size, palette_size, width, height; |
| 113 | int64_t pos; | 115 | int64_t pos; |
| 114 | int format, frames, ret; | 116 | int type, format, frames, ret; |
| 115 | | 117 | |
| 116 | if (avio_feof(pb)) | 118 | if (avio_feof(pb)) |
| 117 | return AVERROR_EOF; | 119 | return AVERROR_EOF; |
| @@ -120,17 +122,18 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 2 unmodified lines |
| 120 | if (!cdxl->read_chunk && | 122 | if (!cdxl->read_chunk && |
| 121 | avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE) | 123 | avio_read(pb, cdxl->header, CDXL_HEADER_SIZE) != CDXL_HEADER_SIZE) |
| 122 | return AVERROR_EOF; | 124 | return AVERROR_EOF; |
| 123 | if (cdxl->header[0] != 1) { | 125 | if (cdxl->header[0] > 1) { |
| 124 | av_log(s, AV_LOG_ERROR, "non-standard cdxl file\n"); | 126 | av_log(s, AV_LOG_ERROR, "unsupported cdxl file\n"); |
| 125 | return AVERROR_INVALIDDATA; | 127 | return AVERROR_INVALIDDATA; |
| 126 | } | 128 | } |
| 127 | | 129 | |
| | 130 | type = cdxl->header[0]; |
| 128 | format = cdxl->header[1] & 0xE0; | 131 | format = cdxl->header[1] & 0xE0; |
| 129 | current_size = AV_RB32(&cdxl->header[2]); | 132 | current_size = AV_RB32(&cdxl->header[2]); |
| 130 | width = AV_RB16(&cdxl->header[14]); | 133 | width = AV_RB16(&cdxl->header[14]); |
| 131 | height = AV_RB16(&cdxl->header[16]); | 134 | height = AV_RB16(&cdxl->header[16]); |
| 132 | palette_size = AV_RB16(&cdxl->header[20]); | 135 | palette_size = AV_RB16(&cdxl->header[20]); |
| 133 | audio_size = AV_RB16(&cdxl->header[22]); | 136 | audio_size = AV_RB16(&cdxl->header[22]) * (1 + !!(cdxl->header[1] & 0x10)); |
| 134 | if (cdxl->header[19] == 0 || | 137 | if (cdxl->header[19] == 0 || |
| 135 | FFALIGN(width, 16) * (uint64_t)height * cdxl->header[19] > INT_MAX) | 138 | FFALIGN(width, 16) * (uint64_t)height * cdxl->header[19] > INT_MAX) |
| 136 | return AVERROR_INVALIDDATA; | 139 | return AVERROR_INVALIDDATA; |
| @@ -140,7 +143,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 3 unmodified lines |
| 140 | image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8; | 143 | image_size = FFALIGN(width, 16) * height * cdxl->header[19] / 8; |
| 141 | video_size = palette_size + image_size; | 144 | video_size = palette_size + image_size; |
| 142 | | 145 | |
| 143 | if (palette_size > 512) | 146 | if ((type == 1 && palette_size > 512) || |
| | 147 | (type == 0 && palette_size > 768)) |
| 144 | return AVERROR_INVALIDDATA; | 148 | return AVERROR_INVALIDDATA; |
| 145 | if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE) | 149 | if (current_size < (uint64_t)audio_size + video_size + CDXL_HEADER_SIZE) |
| 146 | return AVERROR_INVALIDDATA; | 150 | return AVERROR_INVALIDDATA; |
| @@ -153,7 +157,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 6 unmodified lines |
| 153 | | 157 | |
| 154 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | 158 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
| 155 | st->codecpar->codec_tag = 0; | 159 | st->codecpar->codec_tag = 0; |
| 156 | st->codecpar->codec_id = AV_CODEC_ID_PCM_S8; | 160 | st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; |
| 157 | if (cdxl->header[1] & 0x10) { | 161 | if (cdxl->header[1] & 0x10) { |
| 158 | st->codecpar->channels = 2; | 162 | st->codecpar->channels = 2; |
| 159 | st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; | 163 | st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; |
| @@ -189,7 +193,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) · 29 unmodified lines |
| 189 | if (audio_size + video_size && cdxl->filesize > 0) { | 193 | if (audio_size + video_size && cdxl->filesize > 0) { |
| 190 | frames = cdxl->filesize / (audio_size + video_size); | 194 | frames = cdxl->filesize / (audio_size + video_size); |
| 191 | | 195 | |
| 192 | if(cdxl->framerate) | 196 | if (cdxl->framerate) |
| 193 | st->duration = frames; | 197 | st->duration = frames; |
| 194 | else | 198 | else |
| 195 | st->duration = frames * (int64_t)audio_size; | 199 | st->duration = frames * (int64_t)audio_size; |