Bug 261093 - Crash printing pages containing plugin objects. r=tor, sr=roc, a=asa.

This commit is contained in:
kjh-5727%comcast.net 2004-09-24 02:02:38 +00:00
Родитель e31fe4fc6c
Коммит d724a81caa
4 изменённых файлов: 2 добавлений и 302 удалений

Просмотреть файл

@ -1,185 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is developed for mozilla.
*
* The Initial Developer of the Original Code is
* Kenneth Herron <kherron@newsguy.com>.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@nrubsig.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsEPSObjectPS.h"
#include "prprf.h"
/* For details on the EPSF spec, see Adobe specification #5002,
* "Encapsulated PostScript File Format Specification". The document
* structuring conventions are described in Specificion #5001,
* "PostScript Language Document Structuring Conventions Specification".
*/
/** ------------------------------------------------------------------
* Constructor
*/
nsEPSObjectPS::nsEPSObjectPS(const char *aData, unsigned long aDataLength) :
mStatus(NS_ERROR_INVALID_ARG),
mData(nsnull),
mDataLength(0UL),
mCurrPos(nsnull),
mBBllx(0.0),
mBBlly(0.0),
mBBurx(0.0),
mBBury(0.0)
{
mData = aData;
mDataLength = aDataLength;
NS_PRECONDITION(aData != nsnull, "aData == nsnull");
NS_PRECONDITION(aDataLength > 0UL, "No data");
Reset();
Parse();
}
/** ------------------------------------------------------------------
* Read one line from the file handle into the buffer, following rules
* for EPS data. The line terminator is not copied into the buffer.
*
* EPS file lines must be less than 256 characters, not including
* line terminators. Lines may be terminated by CR, LF, CRLF, or LFCR.
* See EPSF spec, section 2.9, "Miscellaneous Constraints".
*
* @param aBuffer Buffer in which to place the EPSF text.
* @param aBufSiz Size of aBuffer
* @param aSrc FILE opened for reading
* @return PR_TRUE if a line could be read into aBuffer successfully.
* PR_FALSE if EOF or an I/O error was encountered without reading
* any data, or if the line being read is too large for
* the buffer.
*/
PRBool
nsEPSObjectPS::EPSFFgets(nsACString& aBuffer)
{
aBuffer.Truncate();
while (1) {
int ch = *mCurrPos++;
if ('\n' == ch) {
/* Eat any following carriage return */
ch = *mCurrPos++;
if ((mCurrPos < (mData + mDataLength)) && ('\r' != ch))
mCurrPos--;
return PR_TRUE;
}
else if ('\r' == ch) {
/* Eat any following line feed */
ch = *mCurrPos++;
if ((mCurrPos < (mData + mDataLength)) && ('\n' != ch))
mCurrPos--;
return PR_TRUE;
}
else if (mCurrPos >= (mData + mDataLength)) {
/* If we read any text before the EOF, return true. */
return !aBuffer.IsEmpty();
}
/* Normal case */
aBuffer.Append((char)ch);
}
}
/** ------------------------------------------------------------------
* Reset current position in data
*/
void
nsEPSObjectPS::Reset()
{
mCurrPos = mData;
}
/** ------------------------------------------------------------------
* Parse the EPSF and initialize the object accordingly.
*/
void
nsEPSObjectPS::Parse()
{
nsCAutoString line;
Reset();
while (EPSFFgets(line)) {
if (PR_sscanf(line.get(), "%%%%BoundingBox: %lf %lf %lf %lf",
&mBBllx, &mBBlly, &mBBurx, &mBBury) == 4) {
mStatus = NS_OK;
return;
}
}
mStatus = NS_ERROR_INVALID_ARG;
}
/** ------------------------------------------------------------------
* Write the EPSF to the specified file handle.
* @return NS_OK if the entire EPSF was written without error, or
* else a suitable error code.
*/
nsresult
nsEPSObjectPS::WriteTo(FILE *aDest)
{
NS_PRECONDITION(NS_SUCCEEDED(mStatus), "Bad status");
nsCAutoString line;
PRBool inPreview = PR_FALSE;
Reset();
while (EPSFFgets(line)) {
if (inPreview) {
/* filter out the print-preview section */
if (StringBeginsWith(line, NS_LITERAL_CSTRING("%%EndPreview")))
inPreview = PR_FALSE;
continue;
}
else if (StringBeginsWith(line, NS_LITERAL_CSTRING("%%BeginPreview:"))){
inPreview = PR_TRUE;
continue;
}
/* Output the EPSF with this platform's line terminator */
fwrite(line.get(), line.Length(), 1, aDest);
putc('\n', aDest);
}
return NS_OK;
}

Просмотреть файл

@ -1,97 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is developed for mozilla.
*
* The Initial Developer of the Original Code is
* Kenneth Herron <kherron@newsguy.com>.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@nrubsig.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSEPSOBJECTPS_H
#define NSEPSOBJECTPS_H
#include <stdio.h>
#include <stdlib.h>
#include "nscore.h"
#include "prtypes.h"
#include "nsString.h"
#include "nsReadableUtils.h"
class nsEPSObjectPS {
public:
/** ---------------------------------------------------
* Constructor
*/
nsEPSObjectPS(const char *aData, unsigned long aDataLength);
/** ---------------------------------------------------
* @return the result code from parsing the EPS data.
* If the return value is not NS_OK, the EPS object is
* invalid and should not be used further.
*/
nsresult GetStatus() { return mStatus; };
/** ---------------------------------------------------
* Return Bounding box coordinates: lower left x,
* lower left y, upper right x, upper right y.
*/
PRFloat64 GetBoundingBoxLLX() { return mBBllx; };
PRFloat64 GetBoundingBoxLLY() { return mBBlly; };
PRFloat64 GetBoundingBoxURX() { return mBBurx; };
PRFloat64 GetBoundingBoxURY() { return mBBury; };
/** ---------------------------------------------------
* Write the EPS object to the provided file stream.
* @return NS_OK if the EPS was written successfully, or
* a suitable error code.
*/
nsresult WriteTo(FILE *aDest);
private:
nsresult mStatus;
const char *mData;
unsigned long mDataLength;
const char *mCurrPos;
PRFloat64 mBBllx,
mBBlly,
mBBurx,
mBBury;
void Parse();
void Reset();
PRBool EPSFFgets(nsACString& aBuffer);
};
#endif /* !NSEPSOBJECTPS_H */

Просмотреть файл

@ -51,8 +51,6 @@
#include "nsEPSObjectPS.h"
#include "nsLocalFile.h"
#include <sys/mman.h>
#include <errno.h>
#include <stdio.h>
#include <math.h>
@ -1380,28 +1378,14 @@ NS_IMETHODIMP nsRenderingContextPS::RetrieveCurrentNativeGraphicData(PRUint32 *
NS_IMETHODIMP nsRenderingContextPS::RenderEPS(const nsRect& aRect, FILE *aDataFile)
{
nsresult rv;
int fd;
const char *data;
size_t datalen;
/* EPSFs aren't supposed to have side effects, so if width or height is
* zero, just return. */
if ((aRect.width == 0) || (aRect.height == 0))
return NS_OK;
/* Get file size */
fseek(aDataFile, 0, SEEK_END);
datalen = ftell(aDataFile);
fflush(aDataFile);
fd = fileno(aDataFile);
data = (const char *)mmap(0, datalen, PROT_READ, MAP_SHARED, fd, 0);
if ((int)data == -1)
return nsresultForErrno(errno);
nsEPSObjectPS eps(data, datalen);
nsEPSObjectPS eps(aDataFile);
if (NS_FAILED(eps.GetStatus())) {
munmap((char *)data, datalen);
return NS_ERROR_INVALID_ARG;
}
@ -1410,8 +1394,6 @@ NS_IMETHODIMP nsRenderingContextPS::RenderEPS(const nsRect& aRect, FILE *aDataFi
rv = mPSObj->render_eps(trect, eps);
munmap((char *)data, datalen);
return rv;
}

Просмотреть файл

@ -226,7 +226,7 @@ nsRenderingContextXp::RenderEPS(const nsRect& aRect, FILE *aDataFile)
fd = fileno(aDataFile);
PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("fileno=%d\n", fd));
data = (const unsigned char *)mmap(0, datalen, PROT_READ, MAP_SHARED, fd, 0);
if ((int)data == -1) {
if (MAP_FAILED == data) {
int saved_errno = errno;
PR_LOG(RenderingContextXpLM, PR_LOG_DEBUG, ("mmap() failure, errno=%s/%d\n",
strerror(saved_errno), saved_errno));