зеркало из https://github.com/mozilla/gecko-dev.git
Bug 263801 Hang when importing invalid address book (csv file)
patch by mark@standard8.demon.co.uk r=bienvenu sr=mscott
This commit is contained in:
Родитель
76d4b71659
Коммит
9319e69150
|
@ -161,6 +161,7 @@ nsresult nsTextAddress::ImportAddresses( PRBool *pAbort, const PRUnichar *pName,
|
||||||
nsresult nsTextAddress::ReadRecord( nsIFileSpec *pSrc, char *pLine, PRInt32 bufferSz, char delim, PRInt32 *pLineLen)
|
nsresult nsTextAddress::ReadRecord( nsIFileSpec *pSrc, char *pLine, PRInt32 bufferSz, char delim, PRInt32 *pLineLen)
|
||||||
{
|
{
|
||||||
PRBool wasTruncated;
|
PRBool wasTruncated;
|
||||||
|
PRBool isEof;
|
||||||
char * pRead;
|
char * pRead;
|
||||||
PRInt32 lineLen = 0;
|
PRInt32 lineLen = 0;
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
@ -175,6 +176,13 @@ nsresult nsTextAddress::ReadRecord( nsIFileSpec *pSrc, char *pLine, PRInt32 buff
|
||||||
wasTruncated = PR_FALSE;
|
wasTruncated = PR_FALSE;
|
||||||
pRead = pLine;
|
pRead = pLine;
|
||||||
pRead += lineLen;
|
pRead += lineLen;
|
||||||
|
pSrc->Eof(&isEof);
|
||||||
|
if (isEof)
|
||||||
|
// If we get an EOF here, then the line isn't complete
|
||||||
|
// so we must have an incorrect file.
|
||||||
|
rv = NS_ERROR_FAILURE;
|
||||||
|
else
|
||||||
|
{
|
||||||
rv = pSrc->ReadLine( &pRead, bufferSz - lineLen, &wasTruncated);
|
rv = pSrc->ReadLine( &pRead, bufferSz - lineLen, &wasTruncated);
|
||||||
if (wasTruncated) {
|
if (wasTruncated) {
|
||||||
pLine[bufferSz - 1] = 0;
|
pLine[bufferSz - 1] = 0;
|
||||||
|
@ -184,7 +192,8 @@ nsresult nsTextAddress::ReadRecord( nsIFileSpec *pSrc, char *pLine, PRInt32 buff
|
||||||
else if (NS_SUCCEEDED( rv)) {
|
else if (NS_SUCCEEDED( rv)) {
|
||||||
lineLen = strlen( pLine);
|
lineLen = strlen( pLine);
|
||||||
}
|
}
|
||||||
} while (NS_SUCCEEDED( rv) && !IsLineComplete( pLine, lineLen, delim));
|
}
|
||||||
|
} while (NS_SUCCEEDED( rv) && !IsLineComplete( pLine, lineLen));
|
||||||
|
|
||||||
*pLineLen = lineLen;
|
*pLineLen = lineLen;
|
||||||
return( rv);
|
return( rv);
|
||||||
|
@ -221,44 +230,19 @@ nsresult nsTextAddress::ReadRecordNumber( nsIFileSpec *pSrc, char *pLine, PRInt3
|
||||||
Find out if the given line appears to be a complete record or
|
Find out if the given line appears to be a complete record or
|
||||||
if it needs more data because the line ends with a quoted value non-terminated
|
if it needs more data because the line ends with a quoted value non-terminated
|
||||||
*/
|
*/
|
||||||
PRBool nsTextAddress::IsLineComplete( const char *pLine, PRInt32 len, char delim)
|
PRBool nsTextAddress::IsLineComplete( const char *pLine, PRInt32 len)
|
||||||
{
|
{
|
||||||
char tab = 9;
|
|
||||||
if (delim == tab)
|
|
||||||
tab = 0;
|
|
||||||
|
|
||||||
PRBool quoted = PR_FALSE;
|
PRBool quoted = PR_FALSE;
|
||||||
PRBool wasDelim = PR_FALSE;
|
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
// always skip white space?
|
if ((*pLine == '"')) {
|
||||||
while (len && ((*pLine == ' ') || (*pLine == tab))) {
|
quoted = !quoted;
|
||||||
|
}
|
||||||
pLine++;
|
pLine++;
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
if (len && wasDelim && (*pLine == '"')) {
|
|
||||||
quoted = PR_TRUE;
|
return !quoted;
|
||||||
wasDelim = PR_FALSE;
|
|
||||||
pLine++;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
else if (len && quoted && (*pLine == '"')) {
|
|
||||||
quoted = PR_FALSE;
|
|
||||||
pLine++;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
else if (len) {
|
|
||||||
if (!quoted && (*pLine == delim))
|
|
||||||
wasDelim = PR_TRUE;
|
|
||||||
else
|
|
||||||
wasDelim = PR_FALSE;
|
|
||||||
pLine++;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (quoted)
|
|
||||||
return( PR_FALSE);
|
|
||||||
return( PR_TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsTextAddress::CountFields( const char *pLine, PRInt32 maxLen, char delim)
|
PRInt32 nsTextAddress::CountFields( const char *pLine, PRInt32 maxLen, char delim)
|
||||||
|
|
|
@ -75,7 +75,7 @@ public:
|
||||||
private:
|
private:
|
||||||
nsresult ProcessLine( const char *pLine, PRInt32 len, nsString& errors);
|
nsresult ProcessLine( const char *pLine, PRInt32 len, nsString& errors);
|
||||||
|
|
||||||
static PRBool IsLineComplete( const char *pLine, PRInt32 len, char delim);
|
static PRBool IsLineComplete( const char *pLine, PRInt32 len);
|
||||||
static PRInt32 CountFields( const char *pLine, PRInt32 maxLen, char delim);
|
static PRInt32 CountFields( const char *pLine, PRInt32 maxLen, char delim);
|
||||||
static void SanitizeSingleLine( nsCString& val);
|
static void SanitizeSingleLine( nsCString& val);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче