Commit 3fdb19ce authored by Francois Cartegnie's avatar Francois Cartegnie

access: rar: skip old volume format string on failure (fix #9835)

parent 15958ae9
...@@ -156,10 +156,14 @@ int RarAccessOpen(vlc_object_t *object) ...@@ -156,10 +156,14 @@ int RarAccessOpen(vlc_object_t *object)
stream_t *s = stream_UrlNew(access, base); stream_t *s = stream_UrlNew(access, base);
if (!s) if (!s)
goto error; goto error;
int count; int count = 0;
rar_file_t **files; rar_file_t **files;
if (RarProbe(s) || RarParse(s, &count, &files) || count <= 0) if ( RarProbe(s) || (
goto error; RarParse(s, &count, &files, false ) &&
RarParse(s, &count, &files, true )
) ||
count <= 0 )
goto error;
rar_file_t *file = NULL; rar_file_t *file = NULL;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (!file && !strcmp(files[i]->name, name)) if (!file && !strcmp(files[i]->name, name))
......
...@@ -281,16 +281,16 @@ typedef struct { ...@@ -281,16 +281,16 @@ typedef struct {
const char *format; const char *format;
int start; int start;
int stop; int stop;
bool b_extonly;
} rar_pattern_t; } rar_pattern_t;
static const rar_pattern_t *FindVolumePattern(const char *location) static const rar_pattern_t *FindVolumePattern(const char *location, bool b_extonly )
{ {
static const rar_pattern_t patterns[] = { static const rar_pattern_t patterns[] = {
{ ".part1.rar", "%s.part%.1d.rar", 2, 9 }, { ".part01.rar", "%s.part%.2d.rar", 2, 99, false }, // new naming
{ ".part01.rar", "%s.part%.2d.rar", 2, 99, }, { ".part001.rar", "%s.part%.3d.rar", 2, 999, false }, // new
{ ".part001.rar", "%s.part%.3d.rar", 2, 999 }, { ".rar", "%s.%c%.2d", 0, 999, true }, // old
{ ".rar", "%s.%c%.2d", 0, 999 }, { NULL, NULL, 0, 0, false },
{ NULL, NULL, 0, 0 },
}; };
const size_t location_size = strlen(location); const size_t location_size = strlen(location);
...@@ -299,18 +299,22 @@ static const rar_pattern_t *FindVolumePattern(const char *location) ...@@ -299,18 +299,22 @@ static const rar_pattern_t *FindVolumePattern(const char *location)
if (location_size < match_size) if (location_size < match_size)
continue; continue;
if ( b_extonly && !patterns[i].b_extonly )
continue;
if (!strcmp(&location[location_size - match_size], patterns[i].match)) if (!strcmp(&location[location_size - match_size], patterns[i].match))
return &patterns[i]; return &patterns[i];
} }
return NULL; return NULL;
} }
int RarParse(stream_t *s, int *count, rar_file_t ***file) int RarParse(stream_t *s, int *count, rar_file_t ***file, bool b_extonly)
{ {
*count = 0; *count = 0;
*file = NULL; *file = NULL;
const rar_pattern_t *pattern = FindVolumePattern(s->psz_path); const rar_pattern_t *pattern = FindVolumePattern(s->psz_path, b_extonly);
int volume_offset = 0; int volume_offset = 0;
char *volume_mrl; char *volume_mrl;
......
...@@ -40,7 +40,7 @@ typedef struct { ...@@ -40,7 +40,7 @@ typedef struct {
int RarProbe(stream_t *); int RarProbe(stream_t *);
void RarFileDelete(rar_file_t *); void RarFileDelete(rar_file_t *);
int RarParse(stream_t *, int *, rar_file_t ***); int RarParse(stream_t *, int *, rar_file_t ***, bool);
int RarAccessOpen(vlc_object_t *); int RarAccessOpen(vlc_object_t *);
void RarAccessClose(vlc_object_t *); void RarAccessClose(vlc_object_t *);
......
...@@ -72,7 +72,9 @@ int RarStreamOpen(vlc_object_t *object) ...@@ -72,7 +72,9 @@ int RarStreamOpen(vlc_object_t *object)
int count; int count;
rar_file_t **files; rar_file_t **files;
const int64_t position = stream_Tell(s->p_source); const int64_t position = stream_Tell(s->p_source);
if (RarParse(s->p_source, &count, &files)) { if (RarParse(s->p_source, &count, &files, false) &&
RarParse(s->p_source, &count, &files, true ) )
{
stream_Seek(s->p_source, position); stream_Seek(s->p_source, position);
msg_Err(s, "Invalid or unsupported RAR archive"); msg_Err(s, "Invalid or unsupported RAR archive");
free(files); free(files);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment