From 7f2e62296514bacfb0ea7d5abf42dc8ccee1aedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Wed, 30 Mar 2022 20:28:03 +0000 Subject: [PATCH] libtags: id3v2: make sure extra id3 tag does not cause infinite loop --- sys/src/cmd/audio/libtags/id3v2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sys/src/cmd/audio/libtags/id3v2.c b/sys/src/cmd/audio/libtags/id3v2.c index 53255d7f0..a2ec8dcf5 100644 --- a/sys/src/cmd/audio/libtags/id3v2.c +++ b/sys/src/cmd/audio/libtags/id3v2.c @@ -366,6 +366,7 @@ tagid3v2(Tagctx *ctx) { int sz, exsz, framesz; int ver, unsync, offset; + int oldpos, newpos; uchar d[10], *b; if(ctx->read(ctx, d, sizeof(d)) != sizeof(d)) @@ -378,6 +379,7 @@ tagid3v2(Tagctx *ctx) return 0; } + oldpos = 0; header: ver = d[3]; unsync = d[5] & (1<<7); @@ -449,11 +451,13 @@ header: if(ctx->read(ctx, ctx->buf, sz) != sz) break; for(b = (uchar*)ctx->buf; (b = memchr(b, 'I', sz - 1 - ((char*)b - ctx->buf))) != nil; b++){ - ctx->seek(ctx, (char*)b - ctx->buf + offset + exsz, 0); + newpos = ctx->seek(ctx, (char*)b - ctx->buf + offset + exsz, 0); if(ctx->read(ctx, d, sizeof(d)) != sizeof(d)) return 0; - if(isid3(d)) + if(isid3(d) && newpos != oldpos){ + oldpos = newpos; goto header; + } } for(b = (uchar*)ctx->buf; (b = memchr(b, 0xff, sz-3)) != nil; b++){ if((b[1] & 0xe0) == 0xe0){