author | Xiaoliang Wang <xiaoliang.wang@amlogic.com> | 2016-03-11 07:06:12 (GMT) |
---|---|---|
committer | Xiaoliang Wang <xiaoliang.wang@amlogic.com> | 2016-03-22 02:08:22 (GMT) |
commit | 2aeb4efeb292037cd64bad19ca59f759be0591ce (patch) | |
tree | c8e25df3fac922c4f8b59259ddb425654fa3bc9c | |
parent | eca40f557d9790a015ebf509c793389d6de2664d (diff) | |
download | SubTitle-2aeb4efeb292037cd64bad19ca59f759be0591ce.zip SubTitle-2aeb4efeb292037cd64bad19ca59f759be0591ce.tar.gz SubTitle-2aeb4efeb292037cd64bad19ca59f759be0591ce.tar.bz2 |
PD #120820: fix ssa subtitle length larger than 1000.
Change-Id: I802e6e7746a10e7f95316b7278ba1c0b126692df
-rw-r--r-- | jni/subtitle/sub_api.c | 2 | ||||
-rw-r--r-- | jni/subtitle/sub_api.h | 2 | ||||
-rw-r--r-- | jni/subtitle/sub_jni.c | 16 |
3 files changed, 12 insertions, 8 deletions
diff --git a/jni/subtitle/sub_api.c b/jni/subtitle/sub_api.c index 5f20b09..c88f508 100644 --- a/jni/subtitle/sub_api.c +++ b/jni/subtitle/sub_api.c @@ -393,7 +393,7 @@ static char *internal_subf_gets(char *s, int fd) } } //add to avoid overflow - if (strlen(s) >= 512) + if (strlen(s) >= LINE_LEN) s = NULL; return s; } diff --git a/jni/subtitle/sub_api.h b/jni/subtitle/sub_api.h index 0b237bc..cecb2b3 100644 --- a/jni/subtitle/sub_api.h +++ b/jni/subtitle/sub_api.h @@ -27,7 +27,7 @@ #define SUB_DIVX 16 /* Maximal length of line of a subtitle */ -#define LINE_LEN 1000 +#define LINE_LEN 1024*5 typedef enum { diff --git a/jni/subtitle/sub_jni.c b/jni/subtitle/sub_jni.c index a6cdf24..6de90ab 100644 --- a/jni/subtitle/sub_jni.c +++ b/jni/subtitle/sub_jni.c @@ -71,23 +71,27 @@ JNIEXPORT jobject JNICALL parseSubtitleFile list_t *entry; jstring jtext; char *textBuf = NULL; + int len = 0; list_for_each(entry, &subdata->list) { i++; subtitle_t *subt = list_entry(entry, subtitle_t, list); LOGE("[parseSubtitleFile](%d,%d)", subt->start, subt->end); - textBuf = (char *)malloc(subt->text.lines * 512); - if (textBuf == NULL) - { + + for (j = 0; j < subt->text.lines; j++) { + len = len + strlen(subt->text.text[j]) + 1; //+1 indicate "\n" for each line + } + textBuf = (char *)malloc(len); + if (textBuf == NULL) { LOGE("malloc text buffer failed!"); goto err; } - memset(textBuf, 0, subt->text.lines * 512); - for (j = 0; j < subt->text.lines; j++) - { + memset(textBuf, 0, len); + for (j = 0; j < subt->text.lines; j++) { strcat(textBuf, subt->text.text[j]); strcat(textBuf, "\n"); } + jbyteArray array = (*env)->NewByteArray(env, strlen(textBuf)); (*env)->SetByteArrayRegion(env, array, 0, strlen(textBuf), textBuf); |