Skip to content

Commit

Permalink
OGG: Fixed invalid loop caused by leading zeroes in meta-tag values
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohlstand committed May 5, 2018
1 parent 3035a48 commit fdb6093
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/codecs/music_ogg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fdb6093

Please sign in to comment.