Solved

InputBaseN() returns different value in ColdFusion 10 and CF2016

Posted on 2016-07-26
5
97 Views
Last Modified: 2016-08-10
We recently upgraded from CF10 to CF2016 and are now getting a 'Cannot convert the value 4.023233417E9 to an integer because it cannot fit inside an integer'. I was able to narrow it down to the initialization of the MD5 buffer. This is the code in question:
<CFSET h = ArrayNew(1)>
<CFSET h[1] = InputBaseN("0x67452301",16)>
<CFSET h[2] = InputBaseN("0xefcdab89",16)>
<CFSET h[3] = InputBaseN("0x98badcfe",16)>
<CFSET h[4] = InputBaseN("0x10325476",16)>

<cfdump var="#h#">

Open in new window


The problem is in the value being returned by the InputbaseN(). On the CF10 server the result looks like this:
1      1732584193
2      -271733879
3      -1732584194
4      271733878

However, on the server running CF2016, it looks like this:
1      1732584193
2      4023233417
3      2562383102
4      271733878

Why would the values for 2&3 change based on the CF version? And is there a way to fix this?
0
Comment
Question by:NEXT IT
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 41729822
Sounds like a bug.  For whatever reason CF2016 is returning the value as a Long (bigger capacity) instead of the expected Integer.  A quick look didn't turn up any settings that might allow you to control that behavior.  I'd file a bug report.  In the mean time, you'll need a workaround. Try using Long.intValue() to get back the original integer:

<CFSET h = ArrayNew(1)>
<CFSET h[1] = InputBaseN("0x67452301",16)>
<CFSET h[2] = InputBaseN("0xefcdab89",16)>
<CFSET h[3] = InputBaseN("0x98badcfe",16)>
<CFSET h[4] = InputBaseN("0x10325476",16)>

<cfoutput>
<cfloop array="#h#" index="longValue">
	<br> Long = #longValue# / Integer = #javacast("long", longValue).intValue()#
</cfloop>
</cfoutput>

Open in new window


Result:
Long = 1732584193 / Integer = 1732584193
Long = 4023233417 / Integer = -271733879
Long = 2562383102 / Integer = -1732584194
Long = 271733878 / Integer = 271733878
0
 

Author Closing Comment

by:NEXT IT
ID: 41729980
Thanks for the help - worked like a charm. Gonna add this to their bug tracker and hope this isn't another one of Adobe's "undocumented features"
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41730044
Yeah, hope not but ... it's kind of a weird change. CF has always had a 32 bit int limit for most functions. To suddenly start returning an unsigned long value without warning ... smacks of something "undocumented" ;-)
0
 

Author Comment

by:NEXT IT
ID: 41733239
Just to circle back on  this... we filed bug https://bugbase.adobe.com/index.cfm?event=bug&id=4175842 with Adobe.

Adobe then came back and said the behavior in CF10 and CF11 was actually wrong they "fixed" it in CF2016 Update 2.  They referenced CF10 bug:

https://bugbase.adobe.com/index.cfm?event=bug&id=3712098

I'm pretty sure our code had worked on CF versions prior to CF10 without issue as well so I'm not sure this explains that, but I can't remember that far back to say for certain.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 41733468
Interesting. Though I am not sure I agree with how they handled it.  CF's long been known to have a 32bit int limit for most functions and operators. So of course some numbers may be too large, and could obviously be truncated when converted to an INT. However, the documentation says:

Description:  Converts string, using the base specified by radix, to an integer.

To me that says the expected result should be an integer. To suddenly decide it will now be a Long, or some other type, breaks backward compatibility.  Why not throw an error, or add a new parameter/setting that defaults to the old behavior, but allows developers to chose which behavior they want on a per app basis?  BTW, if the function is no longer returning a 32 bit integer - do you know what is it returning? I didn't see that mentioned in either bug report.  I'm guessing:

http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#MIN_VALUE
http://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#MAX_VALUE

?

I'm pretty sure our code had worked on CF versions prior to CF10 without issue

Well I suppose if it's something simply dependent on matching output like hashing, or the other system uses ints too, in theory it might work either way.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now