summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-07-12 11:31:03 -0700
committerJohn Stebbins <[email protected]>2019-08-11 15:54:27 -0700
commit93bbc62c454274b8be23705e10438fc0ee31ac24 (patch)
tree0f239a1b6612407259d28bf5d9f04f3ecf637477 /libhb
parent7e5b372eeb3db720b0bc22419f621f40eff6dd87 (diff)
libhb: eliminate file path length limits
Diffstat (limited to 'libhb')
-rw-r--r--libhb/bd.c10
-rw-r--r--libhb/common.c28
-rw-r--r--libhb/common.h12
-rw-r--r--libhb/dvd.c17
-rw-r--r--libhb/dvd.h2
-rw-r--r--libhb/dvdnav.c42
-rw-r--r--libhb/hb.c9
-rw-r--r--libhb/hb_json.c7
-rw-r--r--libhb/internal.h6
-rw-r--r--libhb/scan.c6
-rw-r--r--libhb/stream.c14
11 files changed, 90 insertions, 63 deletions
diff --git a/libhb/bd.c b/libhb/bd.c
index 02508e10b..46ffae3d4 100644
--- a/libhb/bd.c
+++ b/libhb/bd.c
@@ -38,7 +38,7 @@ static int title_info_compare_mpls(const void *, const void *);
***********************************************************************
*
**********************************************************************/
-hb_bd_t * hb_bd_init( hb_handle_t *h, char * path )
+hb_bd_t * hb_bd_init( hb_handle_t *h, const char * path )
{
hb_bd_t * d;
int ii;
@@ -281,14 +281,12 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration )
if (d->disc_info->disc_name != NULL && d->disc_info->disc_name[0] != 0)
{
- strncpy(title->name, d->disc_info->disc_name, sizeof(title->name));
- title->name[sizeof(title->name) - 1] = 0;
+ title->name = strdup(d->disc_info->disc_name);
}
else if (d->disc_info->udf_volume_id != NULL &&
d->disc_info->udf_volume_id[0] != 0)
{
- strncpy(title->name, d->disc_info->udf_volume_id, sizeof(title->name));
- title->name[sizeof(title->name) - 1] = 0;
+ title->name = strdup(d->disc_info->udf_volume_id);
}
else
{
@@ -300,7 +298,7 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration )
p_last = &p_cur[1];
}
}
- snprintf(title->name, sizeof( title->name ), "%s", p_last);
+ title->name = strdup(p_last);
char *dot_term = strrchr(title->name, '.');
if (dot_term)
*dot_term = '\0';
diff --git a/libhb/common.c b/libhb/common.c
index df5d60467..554db5004 100644
--- a/libhb/common.c
+++ b/libhb/common.c
@@ -3681,7 +3681,7 @@ hb_title_t * hb_title_init( char * path, int index )
t->list_subtitle = hb_list_init();
t->list_attachment = hb_list_init();
t->metadata = hb_metadata_init();
- strncat(t->path, path, sizeof(t->path) - 1);
+ t->path = strdup(path);
// default to decoding mpeg2
t->video_id = 0xE0;
t->video_codec = WORK_DECAVCODECV;
@@ -3738,7 +3738,9 @@ void hb_title_close( hb_title_t ** _t )
hb_metadata_close( &t->metadata );
- free( t->video_codec_name );
+ free((char*)t->name);
+ free((char*)t->path);
+ free(t->video_codec_name);
free(t->container_name);
free( t );
@@ -4817,6 +4819,10 @@ hb_subtitle_t *hb_subtitle_copy(const hb_subtitle_t *src)
{
subtitle->config.name = strdup(src->config.name);
}
+ if (src->config.src_filename)
+ {
+ subtitle->config.src_filename = strdup(src->config.src_filename);
+ }
}
return subtitle;
}
@@ -4850,15 +4856,17 @@ hb_list_t *hb_subtitle_list_copy(const hb_list_t *src)
**********************************************************************
*
*********************************************************************/
-void hb_subtitle_close( hb_subtitle_t **sub )
+void hb_subtitle_close( hb_subtitle_t **_sub )
{
- if ( sub && *sub )
+ hb_subtitle_t * sub = *_sub;
+ if ( _sub && sub )
{
- free ((char*)(*sub)->name);
- free ((char*)(*sub)->config.name);
- free ((*sub)->extradata);
- free(*sub);
- *sub = NULL;
+ free((char*)sub->name);
+ free((char*)sub->config.name);
+ free((char*)sub->config.src_filename);
+ free(sub->extradata);
+ free(sub);
+ *_sub = NULL;
}
}
@@ -4919,6 +4927,7 @@ int hb_subtitle_add(const hb_job_t * job, const hb_subtitle_config_t * subtitlec
{
subtitle->config.name = strdup(subtitlecfg->name);
}
+ subtitle->config.src_filename = NULL;
subtitle->out_track = hb_list_count(job->list_subtitle) + 1;
hb_list_add(job->list_subtitle, subtitle);
return 1;
@@ -4962,6 +4971,7 @@ int hb_import_subtitle_add( const hb_job_t * job,
{
subtitle->config.name = strdup(subtitlecfg->name);
}
+ subtitle->config.src_filename = strdup(subtitlecfg->src_filename);
hb_list_add(job->list_subtitle, subtitle);
return 1;
diff --git a/libhb/common.h b/libhb/common.h
index 6cf949881..e5f53b993 100644
--- a/libhb/common.h
+++ b/libhb/common.h
@@ -302,9 +302,9 @@ struct hb_subtitle_config_s
const char * name;
/* SRT subtitle tracks only */
- char src_filename[256];
- char src_codeset[40];
- int64_t offset;
+ const char * src_filename;
+ char src_codeset[40];
+ int64_t offset;
};
/*******************************************************************************
@@ -457,7 +457,7 @@ struct hb_title_set_s
{
hb_list_t * list_title;
int feature; // Detected DVD feature title
- char path[1024];
+ const char * path;
};
typedef enum
@@ -1047,8 +1047,8 @@ struct hb_title_s
{
enum { HB_DVD_TYPE, HB_BD_TYPE, HB_STREAM_TYPE, HB_FF_STREAM_TYPE } type;
uint32_t reg_desc;
- char path[1024];
- char name[1024];
+ const char * path;
+ const char * name;
int index;
int playlist;
int angle_count;
diff --git a/libhb/dvd.c b/libhb/dvd.c
index 08ac79897..fa991bf5c 100644
--- a/libhb/dvd.c
+++ b/libhb/dvd.c
@@ -15,7 +15,7 @@
#include "dvdread/ifo_print.h"
#include "dvdread/nav_read.h"
-static hb_dvd_t * hb_dvdread_init( hb_handle_t * h, char * path );
+static hb_dvd_t * hb_dvdread_init( hb_handle_t * h, const char * path );
static void hb_dvdread_close( hb_dvd_t ** _d );
static char * hb_dvdread_name( char * path );
static int hb_dvdread_title_count( hb_dvd_t * d );
@@ -106,7 +106,7 @@ static char * hb_dvdread_name( char * path )
***********************************************************************
*
**********************************************************************/
-hb_dvd_t * hb_dvdread_init( hb_handle_t * h, char * path )
+hb_dvd_t * hb_dvdread_init( hb_handle_t * h, const char * path )
{
hb_dvd_t * e;
hb_dvdread_t * d;
@@ -310,6 +310,7 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
ifo_handle_t * vts = NULL;
int pgc_id, pgn, i;
hb_chapter_t * chapter;
+ char name[1024];
unsigned char unused[1024];
const char * codec_name;
@@ -318,8 +319,7 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
title = hb_title_init( d->path, t );
title->type = HB_DVD_TYPE;
- if( DVDUDFVolumeInfo( d->reader, title->name, sizeof( title->name ),
- unused, sizeof( unused ) ) )
+ if( DVDUDFVolumeInfo(d->reader, name, sizeof(name), unused, sizeof(unused)))
{
char * p_cur, * p_last = d->path;
for( p_cur = d->path; *p_cur; p_cur++ )
@@ -329,11 +329,15 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
p_last = &p_cur[1];
}
}
- snprintf( title->name, sizeof( title->name ), "%s", p_last );
+ title->name = strdup(p_last);
char *dot_term = strrchr(title->name, '.');
if (dot_term)
*dot_term = '\0';
}
+ else
+ {
+ title->name = strdup(name);
+ }
/* VTS which our title is in */
int title_vts = d->vmg->tt_srpt->title[t-1].title_set_nr;
@@ -1296,6 +1300,7 @@ static void hb_dvdread_close( hb_dvd_t ** _d )
DVDClose( d->reader );
}
+ free( d->path );
free( d );
*_d = NULL;
}
@@ -1378,7 +1383,7 @@ char * hb_dvd_name( char * path )
return dvd_methods->name(path);
}
-hb_dvd_t * hb_dvd_init( hb_handle_t * h, char * path )
+hb_dvd_t * hb_dvd_init( hb_handle_t * h, const char * path )
{
return dvd_methods->init(h, path);
}
diff --git a/libhb/dvd.h b/libhb/dvd.h
index 338c8da89..7ac673ca0 100644
--- a/libhb/dvd.h
+++ b/libhb/dvd.h
@@ -96,7 +96,7 @@ union hb_dvd_s
struct hb_dvd_func_s
{
- hb_dvd_t * (* init) ( hb_handle_t *, char * );
+ hb_dvd_t * (* init) ( hb_handle_t *, const char * );
void (* close) ( hb_dvd_t ** );
char * (* name) ( char * );
int (* title_count) ( hb_dvd_t * );
diff --git a/libhb/dvdnav.c b/libhb/dvdnav.c
index d3a15dad4..061c20f06 100644
--- a/libhb/dvdnav.c
+++ b/libhb/dvdnav.c
@@ -19,7 +19,7 @@
#define DVD_READ_CACHE 1
static char * hb_dvdnav_name( char * path );
-static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, char * path );
+static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path );
static int hb_dvdnav_title_count( hb_dvd_t * d );
static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * d, int t, uint64_t min_duration );
static int hb_dvdnav_start( hb_dvd_t * d, hb_title_t *title, int chapter );
@@ -150,7 +150,7 @@ fail:
***********************************************************************
*
**********************************************************************/
-static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, char * path )
+static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path )
{
hb_dvd_t * e;
hb_dvdnav_t * d;
@@ -458,7 +458,8 @@ static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * e, int t, uint64_t min_dura
hb_chapter_t * chapter;
hb_dvd_chapter_t * dvd_chapter;
int count;
- const char * name;
+ const char * title_string;
+ char name[1024];
unsigned char unused[1024];
const char * codec_name;
@@ -466,30 +467,33 @@ static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * e, int t, uint64_t min_dura
title = hb_title_init( d->path, t );
title->type = HB_DVD_TYPE;
- if (dvdnav_get_title_string(d->dvdnav, &name) == DVDNAV_STATUS_OK)
+ if (dvdnav_get_title_string(d->dvdnav, &title_string) == DVDNAV_STATUS_OK)
{
- strncpy(title->name, name, sizeof(title->name) - 1);
- title->name[sizeof(title->name) - 1] = 0;
+ title->name = strdup(title_string);
}
- if (strlen(title->name) == 0)
+ if (title->name == NULL || title->name[0] == 0)
{
- if( DVDUDFVolumeInfo( d->reader, title->name, sizeof( title->name ),
- unused, sizeof( unused ) ) )
+ free((char*)title->name);
+ if (DVDUDFVolumeInfo(d->reader, name, sizeof(name),
+ unused, sizeof(unused)))
{
-
- char * p_cur, * p_last = d->path;
- for( p_cur = d->path; *p_cur; p_cur++ )
- {
- if( IS_DIR_SEP(p_cur[0]) && p_cur[1] )
+ char * p_cur, * p_last = d->path;
+ for( p_cur = d->path; *p_cur; p_cur++ )
{
- p_last = &p_cur[1];
+ if( IS_DIR_SEP(p_cur[0]) && p_cur[1] )
+ {
+ p_last = &p_cur[1];
+ }
}
+ title->name = strdup(p_last);
+ char *dot_term = strrchr(title->name, '.');
+ if (dot_term)
+ *dot_term = '\0';
}
- snprintf( title->name, sizeof( title->name ), "%s", p_last );
- char *dot_term = strrchr(title->name, '.');
- if (dot_term)
- *dot_term = '\0';
+ else
+ {
+ title->name = strdup(name);
}
}
diff --git a/libhb/hb.c b/libhb/hb.c
index 22e0ab69b..9854d907e 100644
--- a/libhb/hb.c
+++ b/libhb/hb.c
@@ -365,7 +365,7 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index,
hb_title_t * title;
// Check if scanning is necessary.
- if (!strcmp(h->title_set.path, path))
+ if (h->title_set.path != NULL && !strcmp(h->title_set.path, path))
{
// Current title_set path matches requested path.
// Check if the requested title has already been scanned.
@@ -408,6 +408,8 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index,
hb_list_rem( h->title_set.list_title, title );
hb_title_close( &title );
}
+ free((char*)h->title_set.path);
+ h->title_set.path = NULL;
/* Print CPU info here so that it's in all scan and encode logs */
const char *cpu_name = hb_get_cpu_name();
@@ -435,7 +437,8 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index,
void hb_force_rescan( hb_handle_t * h )
{
- h->title_set.path[0] = 0;
+ free((char*)h->title_set.path);
+ h->title_set.path = NULL;
}
/**
@@ -1642,6 +1645,8 @@ void hb_close( hb_handle_t ** _h )
hb_title_close( &title );
}
hb_list_close( &h->title_set.list_title );
+ free((char*)h->title_set.path);
+ h->title_set.path = NULL;
hb_list_close( &h->jobs );
hb_lock_close( &h->state_lock );
diff --git a/libhb/hb_json.c b/libhb/hb_json.c
index 09ef619d7..3cb353a40 100644
--- a/libhb/hb_json.c
+++ b/libhb/hb_json.c
@@ -922,11 +922,13 @@ char* hb_job_to_json( const hb_job_t * job )
// These functions exist only to perform type checking when using
// json_unpack_ex().
+typedef const char * const_str_t;
+
static double* unpack_f(double *f) { return f; }
static int* unpack_i(int *i) { return i; }
static json_int_t* unpack_I(json_int_t *i) { return i; }
static int * unpack_b(int *b) { return b; }
-static const char** unpack_s(const char **s){ return s; }
+static const_str_t* unpack_s(const_str_t *s){ return s; }
static json_t** unpack_o(json_t** o) { return o; }
void hb_json_job_scan( hb_handle_t * h, const char * json_job )
@@ -1633,8 +1635,7 @@ hb_job_t* hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict )
}
else if (importfile != NULL)
{
- strncpy(sub_config.src_filename, importfile, 255);
- sub_config.src_filename[255] = 0;
+ sub_config.src_filename = importfile;
const char * lang = "und";
const char * srtcodeset = "UTF-8";
diff --git a/libhb/internal.h b/libhb/internal.h
index 26a15d7e4..d9a642255 100644
--- a/libhb/internal.h
+++ b/libhb/internal.h
@@ -323,7 +323,7 @@ typedef struct hb_bd_s hb_bd_t;
typedef union hb_dvd_s hb_dvd_t;
typedef struct hb_stream_s hb_stream_t;
-hb_dvd_t * hb_dvd_init( hb_handle_t * h, char * path );
+hb_dvd_t * hb_dvd_init( hb_handle_t * h, const char * path );
int hb_dvd_title_count( hb_dvd_t * );
hb_title_t * hb_dvd_title_scan( hb_dvd_t *, int title, uint64_t min_duration );
int hb_dvd_start( hb_dvd_t *, hb_title_t *title, int chapter );
@@ -337,7 +337,7 @@ int hb_dvd_angle_count( hb_dvd_t * d );
void hb_dvd_set_angle( hb_dvd_t * d, int angle );
int hb_dvd_main_feature( hb_dvd_t * d, hb_list_t * list_title );
-hb_bd_t * hb_bd_init( hb_handle_t *h, char * path );
+hb_bd_t * hb_bd_init( hb_handle_t *h, const char * path );
int hb_bd_title_count( hb_bd_t * d );
hb_title_t * hb_bd_title_scan( hb_bd_t * d, int t, uint64_t min_duration );
int hb_bd_start( hb_bd_t * d, hb_title_t *title );
@@ -353,7 +353,7 @@ int hb_bd_main_feature( hb_bd_t * d, hb_list_t * list_title );
hb_stream_t * hb_bd_stream_open( hb_handle_t *h, hb_title_t *title );
void hb_ts_stream_reset(hb_stream_t *stream);
-hb_stream_t * hb_stream_open(hb_handle_t *h, char * path,
+hb_stream_t * hb_stream_open(hb_handle_t *h, const char * path,
hb_title_t *title, int scan);
void hb_stream_close( hb_stream_t ** );
hb_title_t * hb_stream_title_scan( hb_stream_t *, hb_title_t *);
diff --git a/libhb/scan.c b/libhb/scan.c
index 85aee2b3e..bd314e3db 100644
--- a/libhb/scan.c
+++ b/libhb/scan.c
@@ -295,12 +295,12 @@ static void ScanFunc( void * _data )
}
if (hb_list_count(data->title_set->list_title) > 0)
{
- strncpy(data->title_set->path, data->path, 1024);
- data->title_set->path[1023] = 0;
+ data->title_set->path = strdup(data->path);
}
else
{
- data->title_set->path[0] = 0;
+ free((char*)data->title_set->path);
+ data->title_set->path = NULL;
}
finish:
diff --git a/libhb/stream.c b/libhb/stream.c
index 320b53ec4..fb0fbeb2b 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -813,7 +813,7 @@ static void prune_streams(hb_stream_t *d)
*
**********************************************************************/
hb_stream_t *
-hb_stream_open(hb_handle_t *h, char *path, hb_title_t *title, int scan)
+hb_stream_open(hb_handle_t *h, const char *path, hb_title_t *title, int scan)
{
if (title == NULL)
{
@@ -1052,9 +1052,11 @@ hb_title_t * hb_stream_title_scan(hb_stream_t *stream, hb_title_t * title)
title->type = HB_STREAM_TYPE;
// Copy part of the stream path to the title name
- char *sep = hb_strr_dir_sep(stream->path);
+ char * name = stream->path;
+ char * sep = hb_strr_dir_sep(stream->path);
if (sep)
- strcpy(title->name, sep+1);
+ name = sep + 1;
+ title->name = strdup(name);
char *dot_term = strrchr(title->name, '.');
if (dot_term)
*dot_term = '\0';
@@ -5685,9 +5687,11 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream, hb_title_t *title )
title->type = HB_FF_STREAM_TYPE;
// Copy part of the stream path to the title name
- char *sep = hb_strr_dir_sep(stream->path);
+ char * name = stream->path;
+ char * sep = hb_strr_dir_sep(stream->path);
if (sep)
- strcpy(title->name, sep+1);
+ name = sep + 1;
+ title->name = strdup(name);
char *dot_term = strrchr(title->name, '.');
if (dot_term)
*dot_term = '\0';