| @@ -6,8 +6,8 @@ · 5 unmodified lines |
| 6 | int | 6 | int |
| 7 | tagflac(Tagctx *ctx) | 7 | tagflac(Tagctx *ctx) |
| 8 | { | 8 | { |
| | 9 | int sz, last, type, seektbloff, seektblsz, off; |
| 9 | uint8_t *d; | 10 | uint8_t *d; |
| 10 | int sz, last, type; | | |
| 11 | uint64_t g; | 11 | uint64_t g; |
| 12 | | 12 | |
| 13 | d = (uint8_t*)ctx->buf; | 13 | d = (uint8_t*)ctx->buf; |
| @@ -37,7 +37,12 @@ tagflac(Tagctx *ctx) · 23 unmodified lines |
| 37 | if((d[0] & 0x80) != 0) | 37 | if((d[0] & 0x80) != 0) |
| 38 | last = 1; | 38 | last = 1; |
| 39 | | 39 | |
| 40 | if((d[0] & 0x7f) == 6){ /* 6 = picture */ | 40 | if((d[0] & 0x7f) == 3 && ctx->toc != nil){ /* 3 = seek table */ |
| | 41 | seektbloff = ctx->seek(ctx, 0, 1); |
| | 42 | seektblsz = sz; |
| | 43 | if(ctx->seek(ctx, sz, 1) <= 0) |
| | 44 | return -1; |
| | 45 | }else if((d[0] & 0x7f) == 6){ /* 6 = picture */ |
| 41 | int n, offset; | 46 | int n, offset; |
| 42 | char *mime; | 47 | char *mime; |
| 43 | | 48 | |
| @@ -117,5 +122,31 @@ tagflac(Tagctx *ctx) · 73 unmodified lines |
| 117 | return -1; | 122 | return -1; |
| 118 | } | 123 | } |
| 119 | | 124 | |
| | 125 | if(ctx->toc == nil) |
| | 126 | return 0; |
| | 127 | off = ctx->seek(ctx, 0, 1); |
| | 128 | if(seektbloff <= 0 || off <= seektbloff || ctx->seek(ctx, seektbloff, 0) != seektbloff) |
| | 129 | return 0; |
| | 130 | |
| | 131 | for(; seektblsz >= 18; seektblsz -= 18){ |
| | 132 | if(ctx->read(ctx, d, 18) != 18) |
| | 133 | break; |
| | 134 | |
| | 135 | /* sample offset */ |
| | 136 | g = (uint64_t)beuint(d+0)<<32 | beuint(d+4); |
| | 137 | if(g == ~0ULL) /* placeholder */ |
| | 138 | break; |
| | 139 | g = g * 1000 / ctx->samplerate; |
| | 140 | if(g > INT_MAX) |
| | 141 | break; |
| | 142 | int ms = g; |
| | 143 | |
| | 144 | /* frame offset */ |
| | 145 | g = off + ((uint64_t)beuint(d+8)<<32 | beuint(d+12)); |
| | 146 | if(g > INT_MAX) |
| | 147 | break; |
| | 148 | ctx->toc(ctx, ms, g); |
| | 149 | } |
| | 150 | |
| 120 | return 0; | 151 | return 0; |
| 121 | } | 152 | } |