Title: [278951] trunk
Revision
278951
Author
cdu...@apple.com
Date
2021-06-16 12:58:32 -0700 (Wed, 16 Jun 2021)

Log Message

FileReader.readAsArrayBuffer misses checking for the type of blob param
https://bugs.webkit.org/show_bug.cgi?id=226640
<rdar://problem/79193198>

Reviewed by Youenn Fablet.

Source/WebCore:

The Blob parameter to FileReader.readAsArrayBuffer / readAsBinaryString / readAsText / readAsDataURL
should not be nullable as per the specification:
- https://w3c.github.io/FileAPI/#APIASynch

This patch aligns us with the specification and with the behavior of both Blink and Gecko.

Test: fast/files/filereader-invalid-blob.html

* fileapi/FileReader.cpp:
(WebCore::FileReader::readAsArrayBuffer):
(WebCore::FileReader::readAsBinaryString):
(WebCore::FileReader::readAsText):
(WebCore::FileReader::readAsDataURL):
* fileapi/FileReader.h:
* fileapi/FileReader.idl:

LayoutTests:

Add layout test coverage. I have verified that this test is passing in Firefox and Chrome as well.

* fast/files/filereader-invalid-blob-expected.txt: Added.
* fast/files/filereader-invalid-blob.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (278950 => 278951)


--- trunk/LayoutTests/ChangeLog	2021-06-16 19:14:26 UTC (rev 278950)
+++ trunk/LayoutTests/ChangeLog	2021-06-16 19:58:32 UTC (rev 278951)
@@ -1,3 +1,16 @@
+2021-06-16  Chris Dumez  <cdu...@apple.com>
+
+        FileReader.readAsArrayBuffer misses checking for the type of blob param
+        https://bugs.webkit.org/show_bug.cgi?id=226640
+        <rdar://problem/79193198>
+
+        Reviewed by Youenn Fablet.
+
+        Add layout test coverage. I have verified that this test is passing in Firefox and Chrome as well.
+
+        * fast/files/filereader-invalid-blob-expected.txt: Added.
+        * fast/files/filereader-invalid-blob.html: Added.
+
 2021-06-16  Amir Mark Jr  <amir_m...@apple.com>
 
         [EWS MacOS WK1] imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-snap-003.html is a flaky failure

Added: trunk/LayoutTests/fast/files/filereader-invalid-blob-expected.txt (0 => 278951)


--- trunk/LayoutTests/fast/files/filereader-invalid-blob-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/files/filereader-invalid-blob-expected.txt	2021-06-16 19:58:32 UTC (rev 278951)
@@ -0,0 +1,21 @@
+Make sure that the FileReader operations throw when passed in an invalid blob.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS fileReader.readAsArrayBuffer(undefined) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsArrayBuffer must be an instance of Blob.
+PASS fileReader.readAsArrayBuffer(null) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsArrayBuffer must be an instance of Blob.
+PASS fileReader.readAsArrayBuffer(window) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsArrayBuffer must be an instance of Blob.
+PASS fileReader.readAsBinaryString(undefined) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsBinaryString must be an instance of Blob.
+PASS fileReader.readAsBinaryString(null) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsBinaryString must be an instance of Blob.
+PASS fileReader.readAsBinaryString(window) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsBinaryString must be an instance of Blob.
+PASS fileReader.readAsText(undefined) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsText must be an instance of Blob.
+PASS fileReader.readAsText(null) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsText must be an instance of Blob.
+PASS fileReader.readAsText(window) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsText must be an instance of Blob.
+PASS fileReader.readAsDataURL(undefined) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsDataURL must be an instance of Blob.
+PASS fileReader.readAsDataURL(null) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsDataURL must be an instance of Blob.
+PASS fileReader.readAsDataURL(window) threw exception TypeError: Argument 1 ('blob') to FileReader.readAsDataURL must be an instance of Blob.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/files/filereader-invalid-blob.html (0 => 278951)


--- trunk/LayoutTests/fast/files/filereader-invalid-blob.html	                        (rev 0)
+++ trunk/LayoutTests/fast/files/filereader-invalid-blob.html	2021-06-16 19:58:32 UTC (rev 278951)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Make sure that the FileReader operations throw when passed in an invalid blob.");
+
+let operations = ["readAsArrayBuffer", "readAsBinaryString", "readAsText", "readAsDataURL"];
+let invalidParameters = ["undefined", "null", "window"];
+
+let fileReader = new FileReader();
+for (let operation of operations) {
+    for (let invalidParameter of invalidParameters)
+      shouldThrowErrorName("fileReader." + operation + "(" + invalidParameter + ")", "TypeError");
+}
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (278950 => 278951)


--- trunk/Source/WebCore/ChangeLog	2021-06-16 19:14:26 UTC (rev 278950)
+++ trunk/Source/WebCore/ChangeLog	2021-06-16 19:58:32 UTC (rev 278951)
@@ -1,3 +1,27 @@
+2021-06-16  Chris Dumez  <cdu...@apple.com>
+
+        FileReader.readAsArrayBuffer misses checking for the type of blob param
+        https://bugs.webkit.org/show_bug.cgi?id=226640
+        <rdar://problem/79193198>
+
+        Reviewed by Youenn Fablet.
+
+        The Blob parameter to FileReader.readAsArrayBuffer / readAsBinaryString / readAsText / readAsDataURL
+        should not be nullable as per the specification:
+        - https://w3c.github.io/FileAPI/#APIASynch
+
+        This patch aligns us with the specification and with the behavior of both Blink and Gecko.
+
+        Test: fast/files/filereader-invalid-blob.html
+
+        * fileapi/FileReader.cpp:
+        (WebCore::FileReader::readAsArrayBuffer):
+        (WebCore::FileReader::readAsBinaryString):
+        (WebCore::FileReader::readAsText):
+        (WebCore::FileReader::readAsDataURL):
+        * fileapi/FileReader.h:
+        * fileapi/FileReader.idl:
+
 2021-06-16  Sihui Liu  <sihui_...@apple.com>
 
         Add lock for static cursorMap in MemoryCursor

Modified: trunk/Source/WebCore/fileapi/FileReader.cpp (278950 => 278951)


--- trunk/Source/WebCore/fileapi/FileReader.cpp	2021-06-16 19:14:26 UTC (rev 278950)
+++ trunk/Source/WebCore/fileapi/FileReader.cpp	2021-06-16 19:58:32 UTC (rev 278951)
@@ -89,45 +89,33 @@
     return m_state == LOADING;
 }
 
-ExceptionOr<void> FileReader::readAsArrayBuffer(Blob* blob)
+ExceptionOr<void> FileReader::readAsArrayBuffer(Blob& blob)
 {
-    if (!blob)
-        return { };
+    LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob.url().string().utf8().data(), is<File>(blob) ? downcast<File>(blob).path().utf8().data() : "");
 
-    LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");
-
-    return readInternal(*blob, FileReaderLoader::ReadAsArrayBuffer);
+    return readInternal(blob, FileReaderLoader::ReadAsArrayBuffer);
 }
 
-ExceptionOr<void> FileReader::readAsBinaryString(Blob* blob)
+ExceptionOr<void> FileReader::readAsBinaryString(Blob& blob)
 {
-    if (!blob)
-        return { };
+    LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob.url().string().utf8().data(), is<File>(blob) ? downcast<File>(blob).path().utf8().data() : "");
 
-    LOG(FileAPI, "FileReader: reading as binary: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");
-
-    return readInternal(*blob, FileReaderLoader::ReadAsBinaryString);
+    return readInternal(blob, FileReaderLoader::ReadAsBinaryString);
 }
 
-ExceptionOr<void> FileReader::readAsText(Blob* blob, const String& encoding)
+ExceptionOr<void> FileReader::readAsText(Blob& blob, const String& encoding)
 {
-    if (!blob)
-        return { };
+    LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob.url().string().utf8().data(), is<File>(blob) ? downcast<File>(blob).path().utf8().data() : "");
 
-    LOG(FileAPI, "FileReader: reading as text: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");
-
     m_encoding = encoding;
-    return readInternal(*blob, FileReaderLoader::ReadAsText);
+    return readInternal(blob, FileReaderLoader::ReadAsText);
 }
 
-ExceptionOr<void> FileReader::readAsDataURL(Blob* blob)
+ExceptionOr<void> FileReader::readAsDataURL(Blob& blob)
 {
-    if (!blob)
-        return { };
+    LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob.url().string().utf8().data(), is<File>(blob) ? downcast<File>(blob).path().utf8().data() : "");
 
-    LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", blob->url().string().utf8().data(), is<File>(*blob) ? downcast<File>(*blob).path().utf8().data() : "");
-
-    return readInternal(*blob, FileReaderLoader::ReadAsDataURL);
+    return readInternal(blob, FileReaderLoader::ReadAsDataURL);
 }
 
 ExceptionOr<void> FileReader::readInternal(Blob& blob, FileReaderLoader::ReadType type)

Modified: trunk/Source/WebCore/fileapi/FileReader.h (278950 => 278951)


--- trunk/Source/WebCore/fileapi/FileReader.h	2021-06-16 19:14:26 UTC (rev 278950)
+++ trunk/Source/WebCore/fileapi/FileReader.h	2021-06-16 19:58:32 UTC (rev 278951)
@@ -62,10 +62,10 @@
         DONE = 2
     };
 
-    ExceptionOr<void> readAsArrayBuffer(Blob*);
-    ExceptionOr<void> readAsBinaryString(Blob*);
-    ExceptionOr<void> readAsText(Blob*, const String& encoding);
-    ExceptionOr<void> readAsDataURL(Blob*);
+    ExceptionOr<void> readAsArrayBuffer(Blob&);
+    ExceptionOr<void> readAsBinaryString(Blob&);
+    ExceptionOr<void> readAsText(Blob&, const String& encoding);
+    ExceptionOr<void> readAsDataURL(Blob&);
     void abort();
 
     void doAbort();

Modified: trunk/Source/WebCore/fileapi/FileReader.idl (278950 => 278951)


--- trunk/Source/WebCore/fileapi/FileReader.idl	2021-06-16 19:14:26 UTC (rev 278950)
+++ trunk/Source/WebCore/fileapi/FileReader.idl	2021-06-16 19:58:32 UTC (rev 278951)
@@ -41,12 +41,10 @@
     const unsigned short DONE = 2;
     readonly attribute unsigned short readyState;
 
-    // FIXME: In all four methods found below, the blob parameter should not be nullable.
-    // async read methods
-    undefined readAsArrayBuffer(Blob? blob);
-    undefined readAsBinaryString(Blob? blob);
-    undefined readAsText(Blob? blob, optional DOMString encoding);
-    undefined readAsDataURL(Blob? blob);
+    undefined readAsArrayBuffer(Blob blob);
+    undefined readAsBinaryString(Blob blob);
+    undefined readAsText(Blob blob, optional DOMString encoding);
+    undefined readAsDataURL(Blob blob);
 
     undefined abort();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to