Possible bug found in a krpano javascript method triggered by third party Array.prototype manipulation.

  • I've run across a possible bug in the HTML5 krpano viewer version 1.17.4 (branding free) and it appears the same bug also exists in krpano 1.19 pre-release. I'll try to give as much detail as I can to reproduce the bug.

    The bug in krpano is revealed by a third party javascript library that adds methods to the Array.prototype. The third party code does something like this:

    Code
    Array.prototype.contains = function() {}

    Although manipulating the Array prototype is generally considered a bad practice, there can be legitimate reasons for doing so.

    The krpano javascript appears to be using a for-in loop ( Ex: for(var x in a) ) instead of for(var x = 0; x < a.length; x++) to loop through the contents of an array. The for-in loop enumerates through the members of an object which gives unexpected results since it also loops through the members of the Array.prototype (it also loops through the function names). Here is a stack overflow question / answer that provides more detail about why the for-in loop should be avoided when looping through an Array:

    http://stackoverflow.com/questions/5005…such-a-bad-idea

    Krpano appears to have this for-in loop inside of encrypted / minified function named embedhtml5(). I found this function name inside of the unbranded version of the krpano javascript code. Here is the code inside that function that contains the for-in loop:


    Code
    if ((a = b) && "null" != a) {
    	   if (_[41] == typeof a) {
    	       b = a.split("&");
    	       a = {};	
           for (var j in b)
    	          e = b[j].split("="), a[e[0]] = e[1]
    	   }
    	   for (var p in a)
    	       "xml" != p && L(p, a[p])
    }


    This is minified code inside of the embedhtml5() function. You can see that the variable b is an Array and that a for-in loop is being used to enumerate through it's members.

    If you want to see this bug in action, it can be observed if you disable flash and visit this URL in Chrome:
    http://www.cruzdavisdental.com/home-test

    Once the first panorama loads, pan to the right and click on the large orange arrow and a javascript error will be thrown inside the above mentioned for-in loop. The transition to the next pano will not complete because of the javascript error that is thrown.

    Please let me know if you need any additional details to reproduce this error or have any questions.

    Thanks,
    Adam

  • Klaus,

    You're the best. The for in loop that I thought was in krpano 1.19 pre-release was actually in a different minified third party js library. I tested again and took a closer look and you are correct, the bug is fixed in the latest version. Thank you for the quick response!

    Adam

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!