diff --git a/src/codecs/music_ogg.c b/src/codecs/music_ogg.c index b187a28c..f1240ea2 100644 --- a/src/codecs/music_ogg.c +++ b/src/codecs/music_ogg.c @@ -245,6 +245,27 @@ static int OGG_UpdateSection(OGG_music *music) return 0; } +/* Convert string into integer with clean-up from junk and leading zeroes */ +static ogg_int64_t str_to_ogg_int64(char *param) +{ + char *front = param; + char *back = param; + + /* Find digit between of 1 and 9 at begin */ + while ( (*front != '\0') && ((*front < '1') || (*front > '9')) ) + front++; + + /* Find any non-digit character or NULL */ + back = front; + while ((*back != '\0') && ((*back >= '0') && (*back <= '9'))) + back++; + + /* Put a string terminator into back just in case */ + *back = '\0'; + + return (ogg_int64_t)SDL_strtoull(front, NULL, 0); +} + /* Load an OGG stream from an SDL_RWops object */ static void *OGG_CreateFromRW(SDL_RWops *src, int freesrc) { @@ -300,13 +321,13 @@ static void *OGG_CreateFromRW(SDL_RWops *src, int freesrc) } if (SDL_strcasecmp(argument, "LOOPSTART") == 0) - music->loop_start = (ogg_int64_t)SDL_strtoull(value, NULL, 0); + music->loop_start = str_to_ogg_int64(value); else if (SDL_strcasecmp(argument, "LOOPLENGTH") == 0) { - music->loop_len = (ogg_int64_t)SDL_strtoull(value, NULL, 0); + music->loop_len = str_to_ogg_int64(value); isLoopLength = 1; } else if (SDL_strcasecmp(argument, "LOOPEND") == 0) { isLoopLength = 0; - music->loop_end = (ogg_int64_t)SDL_strtoull(value, NULL, 0); + music->loop_end = str_to_ogg_int64(value); } else if (SDL_strcasecmp(argument, "TITLE") == 0) { meta_tags_set(&music->tags, MIX_META_TITLE, value); } else if (SDL_strcasecmp(argument, "ARTIST") == 0) {