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