From 163e69b6794c077fd753e4cbcdcb441fe6c57e68 Mon Sep 17 00:00:00 2001 From: "katakai%japan.sun.com" Date: Tue, 9 Apr 2002 01:54:09 +0000 Subject: [PATCH] bug 131161 mozilla crashed when open file where there is an chinese name file under the directory check return value of GetUnicodeLeafName() also call Reset() for encoder and decoder to reset the state r=shanjian,sr=darin,a=asa git-svn-id: svn://10.0.0.236/trunk@118518 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsLocalFileUnicode.cpp | 14 ++++++++++++++ .../xpfe/components/filepicker/src/nsFileView.cpp | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mozilla/xpcom/io/nsLocalFileUnicode.cpp b/mozilla/xpcom/io/nsLocalFileUnicode.cpp index c494463d736..e87a1b996ad 100644 --- a/mozilla/xpcom/io/nsLocalFileUnicode.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnicode.cpp @@ -231,6 +231,13 @@ nsFSStringConversion::UCSToNewFS( const PRUnichar* aIn, char** aOut) { PRInt32 inLength = nsCRT::strlen(aIn); PRInt32 outLength; + // Need to clear up the buffer because a encoder returning + // NS_OK_UDEC_MOREINPUT for an unconvertable aIn lead a new + // file name in aIn to be _appended_ to the end of the encoder buffer. + // (bug 133216 and bug 131161) + res= mEncoder->Reset(); + if(NS_FAILED(res)) + return res; res= mEncoder->GetMaxLength(aIn, inLength,&outLength); if(NS_SUCCEEDED(res)) { *aOut = (char*)nsMemory::Alloc(outLength+1); @@ -260,6 +267,13 @@ nsFSStringConversion::FSToNewUCS( const char* aIn, PRUnichar** aOut) { PRInt32 inLength = strlen(aIn); PRInt32 outLength; + // Need to clear up the buffer because a decoder returning + // NS_OK_UDEC_MOREINPUT for an unconvertable aIn lead a new + // file name in aIn to be _appended_ to the end of the decoder buffer. + // (bug 133216 and bug 131161) + res= mDecoder->Reset(); + if(NS_FAILED(res)) + return res; res= mDecoder->GetMaxLength(aIn, inLength,&outLength); if(NS_SUCCEEDED(res)) { *aOut = (PRUnichar*)nsMemory::Alloc(2*(outLength+1)); diff --git a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp index 6fb83a39228..da939acfb0f 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp +++ b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp @@ -649,7 +649,10 @@ nsFileView::FilterFiles() file->IsHidden(&isHidden); nsXPIDLString unicodeLeafName; - file->GetUnicodeLeafName(getter_Copies(unicodeLeafName)); + if(NS_FAILED(file->GetUnicodeLeafName(getter_Copies(unicodeLeafName)))) { + // need to check return value for GetUnicodeLeafName() + continue; + } if (!isHidden) { for (PRInt32 j = 0; j < filterCount; ++j) {