зеркало из https://github.com/mozilla/gecko-dev.git
Bug 446708: ZipWriter incorrectly passes 0 data to onDataAvailable. r=biesi
This commit is contained in:
Родитель
0eed0106e0
Коммит
fc728e3444
|
@ -206,12 +206,16 @@ NS_IMETHODIMP nsDeflateConverter::OnStopRequest(nsIRequest *aRequest,
|
||||||
nsresult nsDeflateConverter::PushAvailableData(nsIRequest *aRequest,
|
nsresult nsDeflateConverter::PushAvailableData(nsIRequest *aRequest,
|
||||||
nsISupports *aContext)
|
nsISupports *aContext)
|
||||||
{
|
{
|
||||||
|
PRUint32 bytesToWrite = sizeof(mWriteBuffer) - mZstream.avail_out;
|
||||||
|
// We don't need to do anything if there isn't any data
|
||||||
|
if (bytesToWrite == 0)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsIStringInputStream> stream =
|
nsCOMPtr<nsIStringInputStream> stream =
|
||||||
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
|
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
PRUint32 bytesToWrite = ZIP_BUFLEN - mZstream.avail_out;
|
|
||||||
stream->ShareData((char*)mWriteBuffer, bytesToWrite);
|
stream->ShareData((char*)mWriteBuffer, bytesToWrite);
|
||||||
rv = mListener->OnDataAvailable(aRequest, mContext, stream, mOffset,
|
rv = mListener->OnDataAvailable(aRequest, mContext, stream, mOffset,
|
||||||
bytesToWrite);
|
bytesToWrite);
|
||||||
|
|
Двоичные данные
modules/libjar/zipwriter/test/unit/data/test_bug446708/thumbs/st14-1.tiff
Normal file
Двоичные данные
modules/libjar/zipwriter/test/unit/data/test_bug446708/thumbs/st14-1.tiff
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,52 @@
|
||||||
|
function run_test() {
|
||||||
|
var testBundle = do_get_file("modules/libjar/zipwriter/test/unit/data/test_bug446708");
|
||||||
|
|
||||||
|
RecursivelyZipDirectory(testBundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add |file| to the zip. |path| is the current path for the file.
|
||||||
|
function AddToZip(zipWriter, path, file)
|
||||||
|
{
|
||||||
|
var currentPath = path + file.leafName;
|
||||||
|
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
currentPath += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
// THIS IS WHERE THE ERROR OCCURS, FOR THE FILE "st14-1.tiff" IN "test_bug446708"
|
||||||
|
zipWriter.addEntryFile(currentPath, Ci.nsIZipWriter.COMPRESSION_DEFAULT, file, false);
|
||||||
|
|
||||||
|
// if it's a dir, continue adding its contents recursively...
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
var entries = file.QueryInterface(Components.interfaces.nsIFile).directoryEntries;
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
var entry = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
|
||||||
|
AddToZip(zipWriter, currentPath, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...otherwise, we're done
|
||||||
|
}
|
||||||
|
|
||||||
|
function RecursivelyZipDirectory(bundle)
|
||||||
|
{
|
||||||
|
// create directory service
|
||||||
|
var dirUtils = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||||
|
.createInstance(Components.interfaces.nsIProperties);
|
||||||
|
|
||||||
|
// get the temp dir, where our temporary zip attachments can be stored
|
||||||
|
var tempFile = dirUtils.get("TmpD", Components.interfaces.nsIFile).clone();
|
||||||
|
|
||||||
|
// create unique file there
|
||||||
|
tempFile.append(bundle.leafName + ".zip");
|
||||||
|
tempFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE,
|
||||||
|
0600);
|
||||||
|
|
||||||
|
zipW.open(tempFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
|
||||||
|
|
||||||
|
AddToZip(zipW, "", bundle);
|
||||||
|
|
||||||
|
// we're done.
|
||||||
|
zipW.close();
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче