Closed Bug 906413 Opened 11 years ago Closed 9 years ago

Blob slice method can not support relativeEnd is Number.MAX_VALUE

Categories

(Core :: DOM: Core & HTML, defect)

23 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: 418716640, Assigned: arun)

References

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36 Steps to reproduce: <meta charset="UTF-8"> <title>FileAPI Test: Blob slice()</title> <link rel="author" title="zhongquansun" href="mailto:418716640@qq.com" /> <link rel="help" href="http://www.w3.org/TR/FileAPI/#slide-method-algo" /> <meta name="flags" content="dom"/> <meta name="assert" content="test blob constructor methed , type property ,size property ,slice method , all of success is pass" /> <link rel="stylesheet" href="/resources/testharness.css" /> <script type="text/javascript" src="/resources/testharness.js"></script> <script type="text/javascript" src="/resources/testharnessreport.js"></script> <body> <div id="log"></div> <script type="text/javascript"> test(function() { var blob = new Blob(['ttwf']); var bl = blob.slice(0,Number.MAX_VALUE); assert_equals( bl.size, 4); }, 'test blob slice for Number.MAX_VALUE'); test(function() { var blob = new Blob(['ttwf']); var bl = blob.slice(Number.MIN_VALUE,Number.MAX_VALUE); assert_equals( bl.size, 4); }, 'test blob slice for Number.MIN_VALUE and Number.MAX_VALUE -2'); </script> </body> </html> Actual results: 2 Fail Expected results: 2 PASS
Component: Untriaged → DOM
Product: Firefox → Core
Attachment #791802 - Attachment mime type: text/plain → text/html
Per spec, slice() is defined as: Blob slice(optional long long start, optional long long end, optional DOMString contentType); WebIDL defines conversion to long long at http://dev.w3.org/2006/webapi/WebIDL/#es-long-long as follows: Set x to sign(x) * floor(abs(x)). Set x to x modulo 2^64. If x is greater than or equal to 2^63, then set x to x − 2^64. Number.MAX_VALUE is the largest positive finite value of the Number type. For an IEEE double, that's some 53-digit binary mantissa times 2^1023 or so. In particular, it's evenly divisibly by 2^64, so when converting it to IDL long long you get 0. So what we implement is exactly what the spec says to do, as far as I can tell: slice(0,0) should be returning a Blob of size 0. Now maybe the spec should be using [Clamp] here? But note that even then the subtractions the spec defines can overflow.
Flags: needinfo?(arun)
Whiteboard: invalid?
Summary: Blob sclice method can not support relativeEnd is Number.MAX_VALUE → Blob slice method can not support relativeEnd is Number.MAX_VALUE
Fx is doing the right thing here. Furthermore, outside of what 'long long' can contain, I think that slice(0, Number.MAX_VALUE) called on a Blob of size 4 should be illegal. I've logged a bug for further boundary checks on start and end: https://www.w3.org/Bugs/Public/show_bug.cgi?id=23140
Flags: needinfo?(arun)
Arun, thanks.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
Actually, per discussion with Arun, reopening. Spec is being changed to [Clamp]. Once we fix bug 827823 this will be fixed automagically.
Status: RESOLVED → REOPENED
Depends on: 827823
Ever confirmed: true
Resolution: INVALID → ---
Whiteboard: invalid?
W3C bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=23140 is resolved | fixed and the "spec fix" using [Clamp] is in the editor's draft: http://dev.w3.org/2006/webapi/FileAPI/#blob WebIDL tweak is sufficient here; further spec prose is not necessary.
(Fixed in spec.; closing.)
Assignee: nobody → arun
Status: REOPENED → RESOLVED
Closed: 11 years ago9 years ago
QA Contact: arun
Resolution: --- → FIXED
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: