Updated FAAD2 binary in order to fix a bug in the progress printing code, which caused a buffer overrun with very long file names.

This commit is contained in:
LoRd_MuldeR 2012-10-27 01:38:20 +02:00
parent a85eb47897
commit 9aeb6b6b64
6 changed files with 412 additions and 2 deletions

View File

@ -24,6 +24,7 @@ a:visited { color: #0000EE; }
<li>Updated MediaInfo to v0.7.60 (2012-09-07), compiled with ICL 12.1.7 and MSVC 10.0 <li>Updated MediaInfo to v0.7.60 (2012-09-07), compiled with ICL 12.1.7 and MSVC 10.0
<li>Updated language files (big thank-you to all contributors !!!) <li>Updated language files (big thank-you to all contributors !!!)
<li>Fixed a bug with the "Store temporary files in your system's default TEMP director" checkbox <li>Fixed a bug with the "Store temporary files in your system's default TEMP director" checkbox
<li>Fixed a buffer overflow in FAAD2 decoder which could cause crashes with very long file names
<li>Fixed a regression in Qt v4.8.3 that broke Drag&amp;Drop support (<a href="https://bugreports.qt-project.org/browse/QTBUG-27265" target="_blank">details #1</a>) (<a href="https://codereview.qt-project.org/35297" target="_blank">details #2</a>) <li>Fixed a regression in Qt v4.8.3 that broke Drag&amp;Drop support (<a href="https://bugreports.qt-project.org/browse/QTBUG-27265" target="_blank">details #1</a>) (<a href="https://codereview.qt-project.org/35297" target="_blank">details #2</a>)
<li>Reworked the "About..." dialog &ndash; now using a custom dialog instead of message boxes <li>Reworked the "About..." dialog &ndash; now using a custom dialog instead of message boxes
</ul><br> </ul><br>

View File

@ -0,0 +1,409 @@
frontend/audio.c | 11 +++++-
frontend/main.c | 89 ++++++++++++++++++++++++++++++++---------
frontend/unicode_support.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++
frontend/unicode_support.h | 21 ++++++++++
include/neaacdec.h | 6 +--
5 files changed, 202 insertions(+), 23 deletions(-)
diff --git a/frontend/audio.c b/frontend/audio.c
index 067ac20..a502c6e 100644
--- a/frontend/audio.c
+++ b/frontend/audio.c
@@ -37,11 +37,14 @@
#include <math.h>
#include <neaacdec.h>
#include "audio.h"
+#include "unicode_support.h"
audio_file *open_audio_file(char *infile, int samplerate, int channels,
int outputFormat, int fileType, long channelMask)
{
+ wchar_t *fileNameW;
+
audio_file *aufile = malloc(sizeof(audio_file));
aufile->outputFormat = outputFormat;
@@ -78,7 +81,13 @@ audio_file *open_audio_file(char *infile, int samplerate, int channels,
aufile->toStdio = 1;
} else {
aufile->toStdio = 0;
- aufile->sndfile = fopen(infile, "wb");
+ aufile->sndfile = NULL;
+ fileNameW = utf8_to_utf16(infile);
+ if(fileNameW)
+ {
+ aufile->sndfile = _wfopen(fileNameW, L"wb");
+ free(fileNameW);
+ }
}
if (aufile->sndfile == NULL)
diff --git a/frontend/main.c b/frontend/main.c
index 04e2058..01a5b7a 100644
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -44,11 +44,13 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
+#include <io.h>
#include <neaacdec.h>
#include <mp4ff.h>
#include "audio.h"
+#include "unicode_support.h"
#ifndef min
#define min(a,b) ( (a) < (b) ? (a) : (b) )
@@ -71,6 +73,8 @@ static void faad_fprintf(FILE *stream, const char *fmt, ...)
vfprintf(stream, fmt, ap);
va_end(ap);
+
+ fflush(stream);
}
}
@@ -443,7 +447,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
NeAACDecFrameInfo frameInfo;
NeAACDecConfigurationPtr config;
- char percents[200];
+ char percents[300];
int percent, old_percent = -1;
int bread, fileread;
int header_type = 0;
@@ -456,11 +460,19 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
aac_buffer b;
+ wchar_t *fileNameW;
+
memset(&b, 0, sizeof(aac_buffer));
if (adts_out)
{
- adtsFile = fopen(adts_fn, "wb");
+ adtsFile = NULL;
+ fileNameW = utf8_to_utf16(adts_fn);
+ if(fileNameW)
+ {
+ adtsFile = _wfopen(fileNameW, L"wb");
+ free(fileNameW);
+ }
if (adtsFile == NULL)
{
faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
@@ -470,20 +482,26 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
if (0 == strcmp(aacfile, "-"))
{
- b.infile = stdin;
+ b.infile = stdin;
#ifdef _WIN32
setmode(fileno(stdin), O_BINARY);
#endif
-
- } else
+ }
+ else
{
- b.infile = fopen(aacfile, "rb");
- if (b.infile == NULL)
- {
- /* unable to open file */
- faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
- return 1;
- }
+ b.infile = NULL;
+ fileNameW = utf8_to_utf16(aacfile);
+ if(fileNameW)
+ {
+ b.infile = _wfopen(fileNameW, L"rb");
+ free(fileNameW);
+ }
+ if (b.infile == NULL)
+ {
+ /* unable to open file */
+ faad_fprintf(stderr, "Error opening file: %s\n", aacfile);
+ return 1;
+ }
}
retval = fseek(b.infile, 0, SEEK_END);
@@ -708,7 +726,7 @@ static int decodeAACfile(char *aacfile, char *sndfile, char *adts_fn, int to_std
if (percent > old_percent)
{
old_percent = percent;
- sprintf(percents, "%d%% decoding %s.", percent, aacfile);
+ _snprintf_s(percents, 300, _TRUNCATE, "[%d%%] decoding %s.", percent, aacfile);
faad_fprintf(stderr, "%s\r", percents);
#ifdef _WIN32
SetConsoleTitle(percents);
@@ -810,7 +828,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
unsigned char *buffer;
int buffer_size;
- char percents[200];
+ char percents[300];
int percent, old_percent = -1;
int first_time = 1;
@@ -821,6 +839,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
unsigned int framesize;
unsigned long timescale;
+ wchar_t *fileNameW;
/* initialise the callback structure */
mp4ff_callback_t *mp4cb = malloc(sizeof(mp4ff_callback_t));
@@ -830,7 +849,14 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
return 1;
}
- mp4File = fopen(mp4file, "rb");
+ mp4File = NULL;
+ fileNameW = utf8_to_utf16(mp4file);
+ if(fileNameW)
+ {
+ mp4File = _wfopen(fileNameW, L"rb");
+ free(fileNameW);
+ }
+
mp4cb->read = read_callback;
mp4cb->seek = seek_callback;
mp4cb->user_data = mp4File;
@@ -847,7 +873,13 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
if (adts_out)
{
- adtsFile = fopen(adts_fn, "wb");
+ adtsFile = NULL;
+ fileNameW = utf8_to_utf16(adts_fn);
+ if(fileNameW)
+ {
+ adtsFile = _wfopen(fileNameW, L"wb");
+ free(fileNameW);
+ }
if (adtsFile == NULL)
{
faad_fprintf(stderr, "Error opening file: %s\n", adts_fn);
@@ -1053,7 +1085,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
if (percent > old_percent)
{
old_percent = percent;
- sprintf(percents, "%d%% decoding %s.", percent, mp4file);
+ _snprintf_s(percents, 300, _TRUNCATE, "[%d%%] decoding %s.", percent, mp4file);
faad_fprintf(stderr, "%s\r", percents);
#ifdef _WIN32
SetConsoleTitle(percents);
@@ -1091,7 +1123,7 @@ static int decodeMP4file(char *mp4file, char *sndfile, char *adts_fn, int to_std
return frameInfo.error;
}
-int main(int argc, char *argv[])
+int faad_main(int argc, char *argv[])
{
int result;
int infoOnly = 0;
@@ -1115,6 +1147,7 @@ int main(int argc, char *argv[])
unsigned char header[8];
float length = 0;
FILE *hMP4File;
+ wchar_t *fileNameW;
/* System dependant types */
#ifdef _WIN32
@@ -1345,7 +1378,13 @@ int main(int argc, char *argv[])
} else {
mp4file = 0;
- hMP4File = fopen(aacFileName, "rb");
+ hMP4File = NULL;
+ fileNameW = utf8_to_utf16(aacFileName);
+ if(fileNameW)
+ {
+ hMP4File = _wfopen(fileNameW, L"rb");
+ free(fileNameW);
+ }
if (!hMP4File)
{
faad_fprintf(stderr, "Error opening file: %s\n", aacFileName);
@@ -1408,3 +1447,15 @@ int main(int argc, char *argv[])
return 0;
}
+
+int wmain(int argc, wchar_t **argv_utf16)
+{
+ int result = 0;
+ char **argv_utf8 = NULL;
+
+ init_commandline_arguments_utf8(argc, &argv_utf8, argv_utf16);
+ result = faad_main(argc, argv_utf8);
+ free_commandline_arguments_utf8(argc, &argv_utf8);
+
+ return result;
+}
diff --git a/frontend/unicode_support.c b/frontend/unicode_support.c
new file mode 100644
index 0000000..21ecd5c
--- /dev/null
+++ b/frontend/unicode_support.c
@@ -0,0 +1,98 @@
+#include "unicode_support.h"
+
+#include <stdio.h>
+#include <windows.h>
+
+char *utf16_to_utf8(const wchar_t *input)
+{
+ char *Buffer;
+ int BuffSize, Result;
+
+ BuffSize = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
+ Buffer = (char*) malloc(sizeof(char) * BuffSize);
+
+ if(!Buffer)
+ {
+ fprintf(stderr, "Error in utf16_to_utf8: Memory allocation failed!\n");
+ return NULL;
+ }
+
+ Result = WideCharToMultiByte(CP_UTF8, 0, input, -1, Buffer, BuffSize, NULL, NULL);
+ return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
+}
+
+wchar_t *utf8_to_utf16(const char *input)
+{
+ wchar_t *Buffer;
+ int BuffSize, Result;
+
+ BuffSize = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
+ Buffer = (wchar_t*) malloc(sizeof(wchar_t) * BuffSize);
+
+ if(!Buffer)
+ {
+ fprintf(stderr, "Error in utf8_to_utf16: Memory allocation failed!\n");
+ return NULL;
+ }
+
+ Result = MultiByteToWideChar(CP_UTF8, 0, input, -1, Buffer, BuffSize);
+ return ((Result > 0) && (Result <= BuffSize)) ? Buffer : NULL;
+}
+
+void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16)
+{
+ int i = 0;
+
+ *argv_utf8 = (char**) malloc(argc * sizeof(char*));
+ if(!(*argv_utf8))
+ {
+ fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
+ exit(-1);
+ }
+
+ for(i = 0; i < argc; i++)
+ {
+ (*argv_utf8)[i] = utf16_to_utf8(argv_utf16[i]);
+ if(!(*argv_utf8)[i])
+ {
+ fprintf(stderr, "Error in init_commandline_arguments_utf8: Memory allocation failed!\n");
+ exit(-1);
+ }
+ }
+}
+
+void free_commandline_arguments_utf8(int argc, char ***argv_utf8)
+{
+ int i = 0;
+
+ if(*argv_utf8 != NULL)
+ {
+ for(i = 0; i < argc; i++)
+ {
+ if((*argv_utf8)[i] != NULL)
+ {
+ free((*argv_utf8)[i]);
+ (*argv_utf8)[i] = NULL;
+ }
+ }
+ free(*argv_utf8);
+ *argv_utf8 = NULL;
+ }
+}
+
+FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8)
+{
+ FILE *ret = NULL;
+ wchar_t *filename_utf16 = utf8_to_utf16(filename_utf8);
+ wchar_t *mode_utf16 = utf8_to_utf16(mode_utf8);
+
+ if(filename_utf16 && mode_utf16)
+ {
+ ret = _wfopen(filename_utf16, mode_utf16);
+ }
+
+ if(filename_utf16) free(filename_utf16);
+ if(mode_utf16) free(mode_utf16);
+
+ return ret;
+}
diff --git a/frontend/unicode_support.h b/frontend/unicode_support.h
new file mode 100644
index 0000000..cc13fd9
--- /dev/null
+++ b/frontend/unicode_support.h
@@ -0,0 +1,21 @@
+#ifndef UNICODE_SUPPORT_H_INCLUDED
+#define UNICODE_SUPPORT_H_INCLUDED
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *utf16_to_utf8(const wchar_t *input);
+wchar_t *utf8_to_utf16(const char *input);
+void init_commandline_arguments_utf8(int argc, char ***argv_utf8, wchar_t **argv_utf16);
+void free_commandline_arguments_utf8(int argc, char ***argv_utf8);
+FILE *fopen_utf8(const char *filename_utf8, const char *mode_utf8);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/include/neaacdec.h b/include/neaacdec.h
index 610a00b..7904175 100644
--- a/include/neaacdec.h
+++ b/include/neaacdec.h
@@ -202,7 +202,7 @@ typedef struct NeAACDecFrameInfo
unsigned char ps;
} NeAACDecFrameInfo;
-char NEAACDECAPI *NeAACDecGetErrorMessage(unsigned char errcode);
+char* NEAACDECAPI NeAACDecGetErrorMessage(unsigned char errcode);
unsigned long NEAACDECAPI NeAACDecGetCapabilities(void);
@@ -235,12 +235,12 @@ void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, long frame);
void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder);
-void NEAACDECAPI *NeAACDecDecode(NeAACDecHandle hDecoder,
+void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
unsigned char *buffer,
unsigned long buffer_size);
-void NEAACDECAPI *NeAACDecDecode2(NeAACDecHandle hDecoder,
+void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
NeAACDecFrameInfo *hInfo,
unsigned char *buffer,
unsigned long buffer_size,

Binary file not shown.

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 6 #define VER_LAMEXP_MINOR_LO 6
#define VER_LAMEXP_TYPE RC #define VER_LAMEXP_TYPE RC
#define VER_LAMEXP_PATCH 2 #define VER_LAMEXP_PATCH 2
#define VER_LAMEXP_BUILD 1158 #define VER_LAMEXP_BUILD 1159
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!) // Tool versions (minimum expected versions!)

View File

@ -58,7 +58,7 @@ g_lamexp_tools[] =
{"6d22d4bbd7ce2162e38f70ac9187bc84eb28233b36ee6c0492d0a6195318782d7f05c444", CPU_TYPE_ALL_ALL, "avs2wav.exe", 13}, {"6d22d4bbd7ce2162e38f70ac9187bc84eb28233b36ee6c0492d0a6195318782d7f05c444", CPU_TYPE_ALL_ALL, "avs2wav.exe", 13},
{"8fe60580f10542c25c81f03e130caf128daa1f825b621d9c7c134d8f06948f8c16f787f2", CPU_TYPE_ALL_ALL, "dcaenc.exe", 20120419}, {"8fe60580f10542c25c81f03e130caf128daa1f825b621d9c7c134d8f06948f8c16f787f2", CPU_TYPE_ALL_ALL, "dcaenc.exe", 20120419},
{"e53a787d4a0319453f4fe48c3145f190fcce7ac4802e521db908771437f6250746116e6c", CPU_TYPE_ALL_ALL, "elevator.exe", UINT_MAX}, {"e53a787d4a0319453f4fe48c3145f190fcce7ac4802e521db908771437f6250746116e6c", CPU_TYPE_ALL_ALL, "elevator.exe", UINT_MAX},
{"9ae98a3fc779f69ee876a3b477fbc35a709ba5066823b2eb62eeb015057c38807e4be51f", CPU_TYPE_ALL_ALL, "faad.exe", 27}, {"f53174553c7e2daa692f020f5ce802109d67585ba44992876399e333c9ae9b9481f6cd3a", CPU_TYPE_ALL_ALL, "faad.exe", 27},
{"446054f9a7f705f1aadc9053ca7b8a86a775499ef159978954ebdea92de056c34f8841f7", CPU_TYPE_ALL_ALL, "flac.exe", 121}, {"446054f9a7f705f1aadc9053ca7b8a86a775499ef159978954ebdea92de056c34f8841f7", CPU_TYPE_ALL_ALL, "flac.exe", 121},
{"52fce35084247acc12cd5d06701c143ade9a0915fc9902bb402abd164ea35f28717432a4", CPU_TYPE_ALL_ALL, "gpgv.exe", 1412}, {"52fce35084247acc12cd5d06701c143ade9a0915fc9902bb402abd164ea35f28717432a4", CPU_TYPE_ALL_ALL, "gpgv.exe", 1412},
{"b3fca757b3567dab75c042e62213c231de378ea0fdd7fe29b733417cd5d3d33558452f94", CPU_TYPE_ALL_ALL, "gpgv.gpg", UINT_MAX}, {"b3fca757b3567dab75c042e62213c231de378ea0fdd7fe29b733417cd5d3d33558452f94", CPU_TYPE_ALL_ALL, "gpgv.gpg", UINT_MAX},