From ba2dad63095e026289dc8d39aa13635fdb805d07 Mon Sep 17 00:00:00 2001 From: cristianadam Date: Thu, 24 Jul 2008 19:26:11 +0000 Subject: [PATCH] Fixed Ticket #1392 (OggDemuxPacketSourceFilter GetCurFile memory allocation causes crashes) git-svn-id: http://svn.xiph.org/trunk@15133 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- .../codecs/cmml/dsfCMMLRawSource/CMMLRawSourceFilter.cpp | 14 +++++++++++--- .../filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp | 14 ++++++++++++-- .../directshow/dsfOggDemux2/OggDemuxPacketSourceFilter.cpp | 14 ++++++++++---- oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxFilter.cpp | 14 +++++++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/oggdsf/src/lib/codecs/cmml/dsfCMMLRawSource/CMMLRawSourceFilter.cpp b/oggdsf/src/lib/codecs/cmml/dsfCMMLRawSource/CMMLRawSourceFilter.cpp index 62c3b100c..060163c51 100644 --- a/oggdsf/src/lib/codecs/cmml/dsfCMMLRawSource/CMMLRawSourceFilter.cpp +++ b/oggdsf/src/lib/codecs/cmml/dsfCMMLRawSource/CMMLRawSourceFilter.cpp @@ -79,9 +79,17 @@ ULONG CMMLRawSourceFilter::GetMiscFlags(void) { STDMETHODIMP CMMLRawSourceFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) { //Return the filename and mediatype of the raw data - - LPOLESTR x = SysAllocString(mFileName.c_str()); - *outFileName = x; + CheckPointer(outFileName, E_POINTER); + *outFileName = NULL; + + if (!mFileName.empty()) { + unsigned int size = sizeof(WCHAR) * (mFileName.size() + 1); + + *outFileName = (LPOLESTR) CoTaskMemAlloc(size); + if (*outFileName != NULL) { + CopyMemory(*outFileName, mFileName.c_str(), size); + } + } return S_OK; } diff --git a/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp b/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp index 1e45ef983..2a456c25e 100644 --- a/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp +++ b/oggdsf/src/lib/codecs/flac/filters/dsfNativeFLACSource/NativeFLACSourceFilter.cpp @@ -104,8 +104,18 @@ ULONG NativeFLACSourceFilter::GetMiscFlags(void) //IFileSource Interface STDMETHODIMP NativeFLACSourceFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) { - LPOLESTR x = SysAllocString(mFileName.c_str()); - *outFileName = x; + CheckPointer(outFileName, E_POINTER); + *outFileName = NULL; + + if (!mFileName.empty()) { + unsigned int size = sizeof(WCHAR) * (mFileName.size() + 1); + + *outFileName = (LPOLESTR) CoTaskMemAlloc(size); + if (*outFileName != NULL) { + CopyMemory(*outFileName, mFileName.c_str(), size); + } + } + return S_OK; } diff --git a/oggdsf/src/lib/core/directshow/dsfOggDemux2/OggDemuxPacketSourceFilter.cpp b/oggdsf/src/lib/core/directshow/dsfOggDemux2/OggDemuxPacketSourceFilter.cpp index 3acf205eb..7d25bb97f 100644 --- a/oggdsf/src/lib/core/directshow/dsfOggDemux2/OggDemuxPacketSourceFilter.cpp +++ b/oggdsf/src/lib/core/directshow/dsfOggDemux2/OggDemuxPacketSourceFilter.cpp @@ -449,11 +449,17 @@ HRESULT OggDemuxPacketSourceFilter::setCustomSourceAndLoad(IFilterDataSource* in //IFileSource Interface STDMETHODIMP OggDemuxPacketSourceFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) { - ////Return the filename and mediatype of the raw data - LPOLESTR x = SysAllocString(mFileName.c_str()); - *outFileName = x; + CheckPointer(outFileName, E_POINTER); + *outFileName = NULL; - //TODO::: + if (!mFileName.empty()) { + unsigned int size = sizeof(WCHAR) * (mFileName.size() + 1); + + *outFileName = (LPOLESTR) CoTaskMemAlloc(size); + if (*outFileName != NULL) { + CopyMemory(*outFileName, mFileName.c_str(), size); + } + } return S_OK; } diff --git a/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxFilter.cpp b/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxFilter.cpp index 27053012d..529fdfbff 100644 --- a/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxFilter.cpp +++ b/oggdsf/src/lib/core/directshow/dsfOggMux/OggMuxFilter.cpp @@ -231,9 +231,17 @@ HRESULT OggMuxFilter::SetFileName(LPCOLESTR inFileName, const AM_MEDIA_TYPE* inM HRESULT OggMuxFilter::GetCurFile(LPOLESTR* outFileName, AM_MEDIA_TYPE* outMediaType) { //Return the filename and mediatype of the raw data - - LPOLESTR x = SysAllocString(mFileName.c_str()); - *outFileName = x; + CheckPointer(outFileName, E_POINTER); + *outFileName = NULL; + + if (!mFileName.empty()) { + unsigned int size = sizeof(WCHAR) * (mFileName.size() + 1); + + *outFileName = (LPOLESTR) CoTaskMemAlloc(size); + if (*outFileName != NULL) { + CopyMemory(*outFileName, mFileName.c_str(), size); + } + } return S_OK; } -- 2.11.4.GIT