Commit 3fdb19ce authored by François Cartegnie's avatar François Cartegnie 🤞

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

parent 15958ae9
......@@ -156,10 +156,14 @@ int RarAccessOpen(vlc_object_t *object)
stream_t *s = stream_UrlNew(access, base);
if (!s)
goto error;
int count;
int count = 0;
rar_file_t **files;
if (RarProbe(s) || RarParse(s, &count, &files) || count <= 0)
goto error;
if ( RarProbe(s) || (
RarParse(s, &count, &files, false ) &&
RarParse(s, &count, &files, true )
) ||
count <= 0 )
goto error;
rar_file_t *file = NULL;
for (int i = 0; i < count; i++) {
if (!file && !strcmp(files[i]->name, name))
......
......@@ -281,16 +281,16 @@ typedef struct {
const char *format;
int start;
int stop;
bool b_extonly;
} 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[] = {
{ ".part1.rar", "%s.part%.1d.rar", 2, 9 },
{ ".part01.rar", "%s.part%.2d.rar", 2, 99, },
{ ".part001.rar", "%s.part%.3d.rar", 2, 999 },
{ ".rar", "%s.%c%.2d", 0, 999 },
{ NULL, NULL, 0, 0 },
{ ".part01.rar", "%s.part%.2d.rar", 2, 99, false }, // new naming
{ ".part001.rar", "%s.part%.3d.rar", 2, 999, false }, // new
{ ".rar", "%s.%c%.2d", 0, 999, true }, // old
{ NULL, NULL, 0, 0, false },
};
const size_t location_size = strlen(location);
......@@ -299,18 +299,22 @@ static const rar_pattern_t *FindVolumePattern(const char *location)
if (location_size < match_size)
continue;
if ( b_extonly && !patterns[i].b_extonly )
continue;
if (!strcmp(&location[location_size - match_size], patterns[i].match))
return &patterns[i];
}
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;
*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;
char *volume_mrl;
......
......@@ -40,7 +40,7 @@ typedef struct {
int RarProbe(stream_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 *);
void RarAccessClose(vlc_object_t *);
......
......@@ -72,7 +72,9 @@ int RarStreamOpen(vlc_object_t *object)
int count;
rar_file_t **files;
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);
msg_Err(s, "Invalid or unsupported RAR archive");
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