bugGnash - The GNU Flash player - Bugs: bug #47280, Gnash's ExternalInterface does not...

 
 

bug #47280: Gnash's ExternalInterface does not return Number value correctly

Submitter:  Nutchanon Wetchasit <nachanon>
Submitted:  Sat 27 Feb 2016 10:13:27 AM UTC
   
 
Category:  plugin Severity:  3 - Normal
Release:  master Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 29 Mar 2016 09:50:41 AM UTC, comment #7: 

We usually try to track as closely as possible the proprietary player as most SWF authors code using the proprietary player as a reference. Sometimes different versions of the proprietary player (PP for short) behave differently and that's why we setup an online repository of our actionscript.all tests to make it easier for different people on the net to report eventual weird behavior (failures) with their version of the player.

Unfortunately the online versions are not available at the moment, but you could produce them with "make online-tests" from under testsuite/actioncsript.all. I guess we'll want to publish them somewhere else and call users for testing.

When the platform makes a difference, we pick the Windows version as the reference one. As for the version, the most stable version should be considered.

Sandro Santilli <strk>
Group Member
Sun 13 Mar 2016 01:07:04 PM UTC, comment #6: 

Note: Some tests are still failing as Flash Player has some quirks/bugs
regarding number value. Some of them are not very easy to investigate:

  • `Infinity` and `-Infinity` return value from JavaScript function are passed as `NaN`.
  • Not all significands in return value of ActionScript callback are passed correctly.


These quirks would need additional testing and discussion before including them in Gnash.

Nutchanon Wetchasit <nachanon>
Sun 13 Mar 2016 01:05:14 PM UTC, comment #5: 

Patch included for fixing `Infinity`/`-Infinity`/`NaN` parsing of ActionScript
callback return value, and precision loss of JavaScript function return value.
See patch #8942.

Relevant text output from `js2flash-rtypes.html` with patched Gnash:

PASSED: Flash callback integer_call should return a correct type
PASSED: Flash callback integer_call should return a correct value
PASSED: Flash callback float_call should return a correct type
PASSED: Flash callback float_call should return a correct value
PASSED: Flash callback infinite_call should return a correct type
PASSED: Flash callback infinite_call should return a correct value
PASSED: Flash callback neginfinite_call should return a correct type
PASSED: Flash callback neginfinite_call should return a correct value
PASSED: Flash callback nan_call should return a correct type
PASSED: Flash callback nan_call should return a correct value


You'd see that `Infinity` return value from `infinite_call(), `-Infinity` from
`neginfinite_call()`, and `NaN` from `nan_call()` are now passed correctly
from ActionScript callback to JavaScript.

Relevant trace output from `flash2js-rtypes.html` with patched Gnash:

82 TRACE: PASSED: JavaScript function integer_call should return a correct type
82 TRACE: PASSED: JavaScript function integer_call should return a correct value
82 TRACE: PASSED: JavaScript function float_call should return a correct type
82 TRACE: PASSED: JavaScript function float_call should return a correct value
83 TRACE: PASSED: JavaScript function infinite_call should return a correct type
83 TRACE: FAILED: JavaScript function infinite_call should return NaN
83 TRACE: PASSED: JavaScript function neginfinite_call should return a correct type
83 TRACE: FAILED: JavaScript function neginfinite_call should return NaN
83 TRACE: PASSED: JavaScript function nan_call should return a correct type
83 TRACE: PASSED: JavaScript function nan_call should return a correct value


You'd see that return value from `float_call()` JavaScript function is now
passed back to ActionScript correctly.

Gnash: 0.8.11dev (patched against git a72afa5 9-Mar-2016) NPAPI
Browser: Iceweasel 10.0.12 (debian)
System: Debian GNU/Linux 7.0 Wheezy i386

Nutchanon Wetchasit <nachanon>
Tue 01 Mar 2016 02:27:44 PM UTC, comment #4: 

The precision problem on Flash-calls-JavaScript return value boils down to how
libgnashplugin marshall floating point number data:

    if (NPVARIANT_IS_DOUBLE(*value)) {
        double num = NPVARIANT_TO_DOUBLE(*value);
        ss << "<number>" << num << "</number>";
    } else if (NPVARIANT_IS_STRING(*value)) {


This causes precision loss as iostream used only few decimal digits when
printing `double` type to the stream. (To losslessly represent the number,
17 decimal significands were required)

Gnash: 0.8.11dev (git c12c3cf 22-Feb-2016)
System: Debian GNU/Linux 7.0 Wheezy i386

Nutchanon Wetchasit <nachanon>
Tue 01 Mar 2016 02:20:51 PM UTC, comment #3: 

The problem on JavaScript-calls-Flash return value boils down to how
libgnashplugin parses `<number>` data from player side:

        } else if (tag == "<number>") {
            start = end;
            end = xml.find("</number>");
            std::string str = xml.substr(start, end-start);
            if (str.find(".") != std::string::npos) {
                double num = strtod(str.c_str(), nullptr);
                DOUBLE_TO_NPVARIANT(num, value);
            } else {
                int num = strtol(str.c_str(), nullptr, 0);
                INT32_TO_NPVARIANT(num, value);
            }


There are few problem with this:

  • It fails when `Infinity`, `-Infinity`, or `NaN` is encountered, as the plugin would parse it as an integer (and results in zero value).
  • It fails when the number is a whole number but is not in `int32_t` range, e.g. 4294967295.


As I understand, plugin's `ExternalInterface::parseXML()` is used only for
parsing player's answer from JavaScript call (both ExternalInterface and
built-in plugin functions), unconditionally parsing the number as `double`
shouldn't cause any problem, as it is same type as JavaScript's `Number`.

Gnash: 0.8.11dev (git c12c3cf 22-Feb-2016)
System: Debian GNU/Linux 7.0 Wheezy i386

Nutchanon Wetchasit <nachanon>
Sat 27 Feb 2016 04:12:36 PM UTC, comment #2: 

On the first post I said `NaN` was returned incorrectly as 0 in
Flash-calls-JavaScript case. That was a mistake, sorry; the `NaN` value
was actually returned correctly in that case.

Updated list of problems:

In JavaScript-calls-Flash scenario:

  • `Infinity` and `-Infinity` are returned incorrectly as 0.
  • `NaN` is returned incorrectly as 0.


In Flash-calls-JavaScript scenario:

  • There is a precision loss (e.g. 1234.5678 got passed as 1234.57).
  • `Infinity` and `-Infinity` are not returned correctly*.


* The `Infinity` and `-Infinity` value in Flash-calls-JavaScript
direction are returned as `NaN` on Flash Player. On Gnash, the actual
`Infinity` or `-Infinity` value is returned.

Nutchanon Wetchasit <nachanon>
Sat 27 Feb 2016 10:21:07 AM UTC, comment #1: 

Original `js2flash-rtypes.html` test is attached as `js2flash-rtypes.zip` (file #36330).
Original `flash2js-rtypes.html` test is attached as `flash2js-rtypes.zip` (file #36331).
Both files were originally posted in bug #47004.

Nutchanon Wetchasit <nachanon>
Sat 27 Feb 2016 10:13:27 AM UTC, original submission:  

This is a spin-off from bug #47004 (ExternalInterface in-band error code issue).

From the result of `js2flash-rtypes.html` and `flash2js-rtypes.html` test
(file #36405) posted in bug #47004, Gnash has few problem on `Number`
type handing of ExternalInterface return value.

In JavaScript-calls-Flash scenario:

  • `Infinity` and `-Infinity` are returned incorrectly as 0.
  • `NaN` is returned incorrectly as 0.


Relevant text output from `js2flash-rtypes.html`:

PASSED: Flash callback float_call should return a correct type
PASSED: Flash callback float_call should return a correct value
PASSED: Flash callback infinite_call should return a correct type
FAILED: Flash callback infinite_call should return a correct value ("0" != "Infinity")
PASSED: Flash callback neginfinite_call should return a correct type
FAILED: Flash callback neginfinite_call should return a correct value ("0" != "-Infinity")
PASSED: Flash callback nan_call should return a correct type
FAILED: Flash callback nan_call should return a correct value


In Flash-calls-JavaScript scenario:

  • There is a precision loss (e.g. 1234.5678 got passed as 1234.57).
  • `Infinity` and `-Infinity` are not returned correctly*.
  • `NaN` is returned incorrectly as 0.


Relevant Gnash's trace output from `flash2js-rtypes.html`:

114 TRACE: PASSED: JavaScript function float_call should return a correct type
114 TRACE: FAILED: JavaScript function float_call should return a correct value ("1234.57" != "1234.5678")
116 TRACE: PASSED: JavaScript function infinite_call should return a correct type
116 TRACE: FAILED: JavaScript function infinite_call should return NaN
117 TRACE: PASSED: JavaScript function neginfinite_call should return a correct type
117 TRACE: FAILED: JavaScript function neginfinite_call should return NaN
118 TRACE: PASSED: JavaScript function nan_call should return a correct type
118 TRACE: PASSED: JavaScript function nan_call should return a correct value


* The `Infinity` and `-Infinity` value on Flash-calls-JavaScript
direction are returned as `NaN` on Flash Player.

Test result, screenshots, text outputs, debug outputs, and GDB backtrace,
are attached as `jsflash-rtypes_roundup.c12c3cf.zip`. (Crash is
due to bug #32411, backtrace is only attached for completeness)
Reference results are in the original test ZIP file.

For the record: According to Adobe's documentation, `Number` is an IEEE-754 `double` type.
The same holds for number in JavaScript (according to Mozilla).

Gnash: 0.8.11dev (git c12c3cf 22-Feb-2016) NPAPI
Browser: Iceweasel 10.0.12 (debian)
System: Debian GNU/Linux 7.0 Wheezy i386

Nutchanon Wetchasit <nachanon>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #36488:  jsflash-rtypes_roundup.c12c3cf.zip added by nachanon (28KiB - application/zip - Outputs, screenshots, and logs from `js2flash-rtypes.html` and `flash2js-rtypes.html` test on Gnash 0.8.11dev git c12c3cf)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by strk (Posted a comment)
  • -email is unavailable- added by nachanon (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-02-27 nachanon Attached File- Added jsflash-rtypes_roundup.c12c3cf.zip, #36488

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code