Bug 1158437 - dom::File should accept negative date values, r=smaug

This commit is contained in:
Andrea Marchesini 2015-04-27 12:17:19 +01:00
parent 5f1707146f
commit d874aacdc8
12 changed files with 96 additions and 55 deletions

View File

@ -161,7 +161,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(File)
/* static */ already_AddRefed<File>
File::Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
uint64_t aLastModifiedDate)
int64_t aLastModifiedDate)
{
nsRefPtr<File> file = new File(aParent,
new FileImplBase(aName, aContentType, aLength, aLastModifiedDate));
@ -199,7 +199,7 @@ File::Create(nsISupports* aParent, const nsAString& aContentType,
File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer,
uint64_t aLength, const nsAString& aName,
const nsAString& aContentType,
uint64_t aLastModifiedDate)
int64_t aLastModifiedDate)
{
nsRefPtr<File> file = new File(aParent,
new FileImplMemory(aMemoryBuffer, aLength, aName,
@ -420,7 +420,7 @@ File::GetType(nsAString &aType)
}
NS_IMETHODIMP
File::GetMozLastModifiedDate(uint64_t* aDate)
File::GetMozLastModifiedDate(int64_t* aDate)
{
MOZ_ASSERT(aDate);

View File

@ -67,7 +67,7 @@ public:
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
uint64_t aLastModifiedDate);
int64_t aLastModifiedDate);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
@ -87,7 +87,7 @@ public:
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
const nsAString& aName, const nsAString& aContentType,
uint64_t aLastModifiedDate);
int64_t aLastModifiedDate);
// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
// freed by free so it must be allocated by malloc or something
@ -276,7 +276,7 @@ public:
virtual void SetLazyData(const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aLastModifiedDate) = 0;
int64_t aLastModifiedDate) = 0;
virtual bool IsMemoryFile() const = 0;
@ -302,7 +302,7 @@ class FileImplBase : public FileImpl
{
public:
FileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate)
uint64_t aLength, int64_t aLastModifiedDate)
: mIsFile(true)
, mImmutable(false)
, mContentType(aContentType)
@ -323,7 +323,7 @@ public:
, mName(aName)
, mStart(0)
, mLength(aLength)
, mLastModificationDate(UINT64_MAX)
, mLastModificationDate(INT64_MAX)
{
// Ensure non-null mContentType by default
mContentType.SetIsVoid(false);
@ -335,7 +335,7 @@ public:
, mContentType(aContentType)
, mStart(0)
, mLength(aLength)
, mLastModificationDate(UINT64_MAX)
, mLastModificationDate(INT64_MAX)
{
// Ensure non-null mContentType by default
mContentType.SetIsVoid(false);
@ -348,7 +348,7 @@ public:
, mContentType(aContentType)
, mStart(aStart)
, mLength(aLength)
, mLastModificationDate(UINT64_MAX)
, mLastModificationDate(INT64_MAX)
{
NS_ASSERTION(aLength != UINT64_MAX,
"Must know length when creating slice");
@ -412,7 +412,7 @@ public:
virtual void
SetLazyData(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate) override
uint64_t aLength, int64_t aLastModifiedDate) override
{
NS_ASSERTION(aLength, "must have length");
@ -430,7 +430,7 @@ public:
virtual bool IsDateUnknown() const override
{
return mIsFile && mLastModificationDate == UINT64_MAX;
return mIsFile && mLastModificationDate == INT64_MAX;
}
virtual bool IsFile() const override
@ -480,7 +480,7 @@ protected:
uint64_t mStart;
uint64_t mLength;
uint64_t mLastModificationDate;
int64_t mLastModificationDate;
// Protected by IndexedDatabaseManager::FileMutex()
nsTArray<nsRefPtr<indexedDB::FileInfo>> mFileInfos;
@ -496,7 +496,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED
FileImplMemory(void* aMemoryBuffer, uint64_t aLength, const nsAString& aName,
const nsAString& aContentType, uint64_t aLastModifiedDate)
const nsAString& aContentType, int64_t aLastModifiedDate)
: FileImplBase(aName, aContentType, aLength, aLastModifiedDate)
, mDataOwner(new DataOwner(aMemoryBuffer, aLength))
{
@ -625,7 +625,7 @@ public:
// Create as a file
explicit FileImplFile(nsIFile* aFile, bool aTemporary = false)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -638,7 +638,7 @@ public:
}
FileImplFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -667,7 +667,7 @@ public:
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
uint64_t aLastModificationDate)
int64_t aLastModificationDate)
: FileImplBase(aName, aContentType, aLength, aLastModificationDate)
, mFile(aFile)
, mWholeFile(true)
@ -680,7 +680,7 @@ public:
// Create as a file with custom name
FileImplFile(nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType)
: FileImplBase(aName, aContentType, UINT64_MAX, UINT64_MAX)
: FileImplBase(aName, aContentType, UINT64_MAX, INT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -722,7 +722,7 @@ public:
// Create as a file to be later initialized
FileImplFile()
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
, mWholeFile(true)
, mStoredFile(false)
, mIsTemporary(false)

View File

@ -187,10 +187,10 @@ void
MultipartFileImpl::SetLengthAndModifiedDate()
{
MOZ_ASSERT(mLength == UINT64_MAX);
MOZ_ASSERT(mLastModificationDate == UINT64_MAX);
MOZ_ASSERT(mLastModificationDate == INT64_MAX);
uint64_t totalLength = 0;
uint64_t lastModified = 0;
int64_t lastModified = 0;
bool lastModifiedSet = false;
for (uint32_t index = 0, count = mBlobImpls.Length(); index < count; index++) {
@ -209,7 +209,7 @@ MultipartFileImpl::SetLengthAndModifiedDate()
totalLength += subBlobLength;
if (blob->IsFile()) {
uint64_t partLastModified = blob->GetLastModified(error);
int64_t partLastModified = blob->GetLastModified(error);
MOZ_ALWAYS_TRUE(!error.Failed());
if (lastModified < partLastModified) {
@ -365,7 +365,8 @@ MultipartFileImpl::InitializeChromeFile(nsPIDOMWindow* aWindow,
}
// Pre-cache modified date.
aRv = blob->GetMozLastModifiedDate(&unused);
int64_t unusedDate;
aRv = blob->GetMozLastModifiedDate(&unusedDate);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -54,7 +54,7 @@ interface nsIDOMBlob : nsISupports
[notxpcom] bool isMemoryFile();
};
[scriptable, builtinclass, uuid(4e7d1a8b-e2d5-4304-a753-4affb731660c)]
[scriptable, builtinclass, uuid(74657f92-aa61-492b-8649-fd1cca62e255)]
interface nsIDOMFile : nsIDOMBlob
{
readonly attribute DOMString name;
@ -69,5 +69,5 @@ interface nsIDOMFile : nsIDOMBlob
// This performs no security checks!
[noscript] readonly attribute DOMString mozFullPathInternal;
[noscript] readonly attribute uint64_t mozLastModifiedDate;
[noscript] readonly attribute int64_t mozLastModifiedDate;
};

View File

@ -781,3 +781,4 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g'
skip-if = buildapp == 'mulet' || buildapp == 'b2g'
[test_integer_attr_with_leading_zero.html]
[test_script_loader_crossorigin_data_url.html]
[test_file_negative_date.html]

View File

@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1158437
-->
<head>
<title>Test for negative date in File (Bug 1158437)</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="fileutils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1158437">Mozilla Bug 1158437</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript;version=1.7">
"use strict";
var blob = new Blob(['hello world']);
var f1 = new File([blob], 'f1.txt', { lastModified: 0 });
var f2 = new File([blob], 'f2.txt', { lastModified: -1 });
var f3 = new File([blob], 'f3.txt', { lastModified: -1000 });
is(f1.lastModified, 0, "lastModified == 0 is supported");
ok(f1.lastModifiedDate.toString(), (new Date(0)).toString(), "Correct f1.lastModifiedDate value");
is(f2.lastModified, -1, "lastModified == -1 is supported");
ok(f2.lastModifiedDate.toString(), (new Date(-1)).toString(), "Correct f2.lastModifiedDate value");
is(f3.lastModified, -1000, "lastModified == -1000 is supported");
ok(f3.lastModifiedDate.toString(), (new Date(-1000)).toString(), "Correct f3.lastModifiedDate value");
</script>
</pre>
</body>
</html>

View File

@ -166,7 +166,7 @@ FileSystemTaskBase::GetBlobParent(nsIDOMFile* aFile) const
aFile->GetType(mimeType);
uint64_t fileSize;
aFile->GetSize(&fileSize);
uint64_t lastModifiedDate;
int64_t lastModifiedDate;
aFile->GetMozLastModifiedDate(&lastModifiedDate);
ContentParent* cp = static_cast<ContentParent*>(mRequestParent->Manager());

View File

@ -159,12 +159,12 @@ struct MOZ_STACK_CLASS BlobOrFileData final
uint64_t size;
nsString type;
nsString name;
uint64_t lastModifiedDate;
int64_t lastModifiedDate;
BlobOrFileData()
: tag(0)
, size(0)
, lastModifiedDate(UINT64_MAX)
, lastModifiedDate(INT64_MAX)
{
MOZ_COUNT_CTOR(BlobOrFileData);
}
@ -333,7 +333,7 @@ StructuredCloneWriteCallback(JSContext* aCx,
}
if (blob->IsFile()) {
uint64_t lastModifiedDate;
int64_t lastModifiedDate;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
blob->GetMozLastModifiedDate(&lastModifiedDate)));
@ -541,9 +541,9 @@ ReadBlobOrFile(JSStructuredCloneReader* aReader,
MOZ_ASSERT(aTag == SCTAG_DOM_FILE ||
aTag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE);
uint64_t lastModifiedDate;
int64_t lastModifiedDate;
if (aTag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE) {
lastModifiedDate = UINT64_MAX;
lastModifiedDate = INT64_MAX;
} else {
if (NS_WARN_IF(!JS_ReadBytes(aReader, &lastModifiedDate,
sizeof(lastModifiedDate)))) {

View File

@ -667,7 +667,7 @@ public:
EmptyBlobImpl(const nsAString& aName,
const nsAString& aContentType,
uint64_t aLastModifiedDate)
int64_t aLastModifiedDate)
: FileImplBase(aName, aContentType, 0, aLastModifiedDate)
{
mImmutable = true;
@ -728,13 +728,13 @@ public:
SameProcessInputStreamBlobImpl(const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aLastModifiedDate,
int64_t aLastModifiedDate,
nsIInputStream* aInputStream)
: FileImplBase(aName, aContentType, aLength, aLastModifiedDate)
, mInputStream(aInputStream)
{
MOZ_ASSERT(aLength != UINT64_MAX);
MOZ_ASSERT(aLastModifiedDate != UINT64_MAX);
MOZ_ASSERT(aLastModifiedDate != INT64_MAX);
MOZ_ASSERT(aInputStream);
mImmutable = true;
@ -766,7 +766,7 @@ struct MOZ_STACK_CLASS CreateBlobImplMetadata final
nsString mContentType;
nsString mName;
uint64_t mLength;
uint64_t mLastModifiedDate;
int64_t mLastModifiedDate;
bool mHasRecursed;
const bool mIsSameProcessActor;
@ -1040,7 +1040,7 @@ CreateBlobImpl(const ParentBlobConstructorParams& aParams,
return nullptr;
}
if (NS_WARN_IF(params.modDate() == UINT64_MAX)) {
if (NS_WARN_IF(params.modDate() == INT64_MAX)) {
ASSERT_UNLESS_FUZZING();
return nullptr;
}
@ -1849,7 +1849,7 @@ public:
const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aModDate);
int64_t aModDate);
// For Blob.
RemoteBlobImpl(BlobChild* aActor,
@ -1862,7 +1862,7 @@ public:
const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aModDate);
int64_t aModDate);
// For same-process blobs.
RemoteBlobImpl(BlobChild* aActor,
@ -2120,7 +2120,7 @@ public:
SetLazyData(const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aLastModifiedDate) override;
int64_t aLastModifiedDate) override;
virtual bool
IsMemoryFile() const override;
@ -2163,7 +2163,7 @@ RemoteBlobImpl::RemoteBlobImpl(BlobChild* aActor,
const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aModDate)
int64_t aModDate)
: FileImplBase(aName, aContentType, aLength, aModDate)
, mIsSlice(false)
{
@ -2186,7 +2186,7 @@ RemoteBlobImpl::RemoteBlobImpl(BlobChild* aActor,
const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aModDate)
int64_t aModDate)
: FileImplBase(aName, aContentType, aLength, aModDate)
, mSameProcessFileImpl(aSameProcessBlobImpl)
, mIsSlice(false)
@ -2214,7 +2214,7 @@ RemoteBlobImpl::RemoteBlobImpl(BlobChild* aActor,
BlobChild::
RemoteBlobImpl::RemoteBlobImpl(BlobChild* aActor)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, INT64_MAX)
, mIsSlice(false)
{
CommonInit(aActor);
@ -2866,7 +2866,7 @@ BlobParent::
RemoteBlobImpl::SetLazyData(const nsAString& aName,
const nsAString& aContentType,
uint64_t aLength,
uint64_t aLastModifiedDate)
int64_t aLastModifiedDate)
{
MOZ_CRASH("This should never be called!");
}
@ -3086,7 +3086,7 @@ BlobChild::CommonInit(BlobChild* aOther, FileImpl* aBlobImpl)
nsString name;
otherImpl->GetName(name);
uint64_t modDate = otherImpl->GetLastModified(rv);
int64_t modDate = otherImpl->GetLastModified(rv);
MOZ_ASSERT(!rv.Failed());
remoteBlob = new RemoteBlobImpl(this, name, contentType, length, modDate);
@ -3156,7 +3156,7 @@ BlobChild::CommonInit(const ChildBlobConstructorParams& aParams)
nsString name;
blobImpl->GetName(name);
uint64_t lastModifiedDate = blobImpl->GetLastModified(rv);
int64_t lastModifiedDate = blobImpl->GetLastModified(rv);
MOZ_ASSERT(!rv.Failed());
remoteBlob =
@ -3345,7 +3345,7 @@ BlobChild::GetOrCreateFromImpl(ChildManagerType* aManager,
nsString name;
aBlobImpl->GetName(name);
uint64_t modDate = aBlobImpl->GetLastModified(rv);
int64_t modDate = aBlobImpl->GetLastModified(rv);
MOZ_ASSERT(!rv.Failed());
blobParams =
@ -3522,12 +3522,12 @@ bool
BlobChild::SetMysteryBlobInfo(const nsString& aName,
const nsString& aContentType,
uint64_t aLength,
uint64_t aLastModifiedDate)
int64_t aLastModifiedDate)
{
AssertIsOnOwningThread();
MOZ_ASSERT(mBlobImpl);
MOZ_ASSERT(mRemoteBlobImpl);
MOZ_ASSERT(aLastModifiedDate != UINT64_MAX);
MOZ_ASSERT(aLastModifiedDate != INT64_MAX);
mBlobImpl->SetLazyData(aName, aContentType, aLength, aLastModifiedDate);
@ -3549,7 +3549,7 @@ BlobChild::SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength)
nsString voidString;
voidString.SetIsVoid(true);
mBlobImpl->SetLazyData(voidString, aContentType, aLength, UINT64_MAX);
mBlobImpl->SetLazyData(voidString, aContentType, aLength, INT64_MAX);
NormalBlobConstructorParams params(aContentType,
aLength,
@ -3887,7 +3887,7 @@ BlobParent::GetOrCreateFromImpl(ParentManagerType* aManager,
nsString name;
aBlobImpl->GetName(name);
uint64_t modDate = aBlobImpl->GetLastModified(rv);
int64_t modDate = aBlobImpl->GetLastModified(rv);
MOZ_ASSERT(!rv.Failed());
blobParams =
@ -4369,7 +4369,7 @@ BlobParent::RecvResolveMystery(const ResolveMysteryParams& aParams)
mBlobImpl->SetLazyData(voidString,
params.contentType(),
params.length(),
UINT64_MAX);
INT64_MAX);
return true;
}
@ -4386,7 +4386,7 @@ BlobParent::RecvResolveMystery(const ResolveMysteryParams& aParams)
return false;
}
if (NS_WARN_IF(params.modDate() == UINT64_MAX)) {
if (NS_WARN_IF(params.modDate() == INT64_MAX)) {
ASSERT_UNLESS_FUZZING();
return false;
}

View File

@ -112,7 +112,7 @@ public:
SetMysteryBlobInfo(const nsString& aName,
const nsString& aContentType,
uint64_t aLength,
uint64_t aLastModifiedDate);
int64_t aLastModifiedDate);
// Use this for non-file blobs.
bool

View File

@ -66,7 +66,7 @@ struct FileBlobConstructorParams
nsString name;
nsString contentType;
uint64_t length;
uint64_t modDate;
int64_t modDate;
// This must be of type BlobData in a child->parent message, and will always
// be of type void_t in a parent->child message.

View File

@ -390,7 +390,7 @@ MmsMessage::GetData(ContentParent* aParent,
// send a "Mystery Blob" to the ContentChild. Attempting to get the
// last modified date of blob can force that value to be initialized.
if (element.content->IsDateUnknown()) {
uint64_t date;
int64_t date;
if (NS_FAILED(element.content->GetMozLastModifiedDate(&date))) {
NS_WARNING("Failed to get last modified date!");
}