#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 User updated by: jian at theorchard dot com Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: Did you not read my previous post? That's the same exactly function I have already posted. Yes, it is very stupid to have to do that on the user's end. Previous Comments: [2010-02-19 05:15:56] ras...@php.net Why can't you always use a signed checksum if that is what you want? crc32 simply returns 32 bits. You always get the same 32 bits regardless of the platform. If you want to always represent that as a signed 32-bit integer, then do so. The fact that some platforms have the ability to show those 32 bits without messing up the sign is irrelevant. Just emulate it with something stupidly simple like: $max32 = 2147483648; $crc = crc32(884385799717_1_1); if($crc$max32-1) { $crc = $crc-2*$max32; } echo $crc; [2010-02-19 04:20:00] jian at theorchard dot com All I was saying is to point out that crc32 function is unable to return the same result represented in the same way under any different platforms. The documentation does say to use sprintf function to format the result to be an unsigned integer in order to the get same expected result from all platforms. In the real world, we actually do need to use signed checksum in some cases. So with this shortcoming in mind, crc32 function cannot achieve a truly signed checksum purpose. [2010-02-18 08:34:59] ras...@php.net It does return the correct set of bits. Anything we do to change what is currently being returned will seriously confuse everyone and the documentation is quite clear on this. [2010-02-18 08:26:44] jian at theorchard dot com On a second thought, however, this still poses an issue. As a programmer, I shouldn't be worreid about all these reformatting and work-arounds. If my function returns me a chicken under development environment, it shouldn't return me an egg once it's released to the production environment. Even though it's the same value, they should also be represented in the same way regardless which platform this function is used. This issue should still be classified as a valid bug in my opinion. [2010-02-17 22:38:09] jian at theorchard dot com Thanks Derick. That was much more helpful. Unfortunately, I cannot use unsigned integer as our checksum. It has to be signed. I do in fact have a work around function built to solve this issue. I was just wondering whether this will get fixed in the future or not. Since it's a platform dependent issue, it most likely won't get fixed I think. Below is the function I have posted against the crc32 function as a note. I hope this can help others out. Thanks again. function get_signed_int($in) { $int_max = pow(2, 31)-1; if ($in $int_max){ $out = $in - $int_max * 2 - 2; } else { $out = $in; } return $out; } The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 Updated by: paj...@php.net Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: Not too hard to understand that PHP has no unsigned integer type. Previous Comments: [2010-02-19 13:33:47] jian at theorchard dot com Did you not read my previous post? That's the same exactly function I have already posted. Yes, it is very stupid to have to do that on the user's end. [2010-02-19 05:15:56] ras...@php.net Why can't you always use a signed checksum if that is what you want? crc32 simply returns 32 bits. You always get the same 32 bits regardless of the platform. If you want to always represent that as a signed 32-bit integer, then do so. The fact that some platforms have the ability to show those 32 bits without messing up the sign is irrelevant. Just emulate it with something stupidly simple like: $max32 = 2147483648; $crc = crc32(884385799717_1_1); if($crc$max32-1) { $crc = $crc-2*$max32; } echo $crc; [2010-02-19 04:20:00] jian at theorchard dot com All I was saying is to point out that crc32 function is unable to return the same result represented in the same way under any different platforms. The documentation does say to use sprintf function to format the result to be an unsigned integer in order to the get same expected result from all platforms. In the real world, we actually do need to use signed checksum in some cases. So with this shortcoming in mind, crc32 function cannot achieve a truly signed checksum purpose. [2010-02-18 08:34:59] ras...@php.net It does return the correct set of bits. Anything we do to change what is currently being returned will seriously confuse everyone and the documentation is quite clear on this. [2010-02-18 08:26:44] jian at theorchard dot com On a second thought, however, this still poses an issue. As a programmer, I shouldn't be worreid about all these reformatting and work-arounds. If my function returns me a chicken under development environment, it shouldn't return me an egg once it's released to the production environment. Even though it's the same value, they should also be represented in the same way regardless which platform this function is used. This issue should still be classified as a valid bug in my opinion. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 Updated by: ras...@php.net Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: But, like I said there is nothing to do here. We have to return the exact bits. Anything we do other than that will cause all sorts of chaos and confusion. So I don't understand what you are asking for, A new datatype in PHP for this? That's not going to happen obviously. Previous Comments: [2010-02-19 13:36:39] paj...@php.net Not too hard to understand that PHP has no unsigned integer type. [2010-02-19 13:33:47] jian at theorchard dot com Did you not read my previous post? That's the same exactly function I have already posted. Yes, it is very stupid to have to do that on the user's end. [2010-02-19 05:15:56] ras...@php.net Why can't you always use a signed checksum if that is what you want? crc32 simply returns 32 bits. You always get the same 32 bits regardless of the platform. If you want to always represent that as a signed 32-bit integer, then do so. The fact that some platforms have the ability to show those 32 bits without messing up the sign is irrelevant. Just emulate it with something stupidly simple like: $max32 = 2147483648; $crc = crc32(884385799717_1_1); if($crc$max32-1) { $crc = $crc-2*$max32; } echo $crc; [2010-02-19 04:20:00] jian at theorchard dot com All I was saying is to point out that crc32 function is unable to return the same result represented in the same way under any different platforms. The documentation does say to use sprintf function to format the result to be an unsigned integer in order to the get same expected result from all platforms. In the real world, we actually do need to use signed checksum in some cases. So with this shortcoming in mind, crc32 function cannot achieve a truly signed checksum purpose. [2010-02-18 08:34:59] ras...@php.net It does return the correct set of bits. Anything we do to change what is currently being returned will seriously confuse everyone and the documentation is quite clear on this. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 User updated by: jian at theorchard dot com Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: As I had previously said, forget it because it's platform related issue not PHP's fault. I was trying to say it would be nice if the end user didn't need to do this kind of re-formatting. It would nice the function acts as a black box. That's all. Thank you all for replying to my post. And I feel very sorry to have wasted all of you time on this stupidity. At least my boss was very understanding what I had to deal with. Please close this ticket. I'm not going to post anything more here. Thank you. Previous Comments: [2010-02-19 13:39:56] ras...@php.net But, like I said there is nothing to do here. We have to return the exact bits. Anything we do other than that will cause all sorts of chaos and confusion. So I don't understand what you are asking for, A new datatype in PHP for this? That's not going to happen obviously. [2010-02-19 13:36:39] paj...@php.net Not too hard to understand that PHP has no unsigned integer type. [2010-02-19 13:33:47] jian at theorchard dot com Did you not read my previous post? That's the same exactly function I have already posted. Yes, it is very stupid to have to do that on the user's end. [2010-02-19 05:15:56] ras...@php.net Why can't you always use a signed checksum if that is what you want? crc32 simply returns 32 bits. You always get the same 32 bits regardless of the platform. If you want to always represent that as a signed 32-bit integer, then do so. The fact that some platforms have the ability to show those 32 bits without messing up the sign is irrelevant. Just emulate it with something stupidly simple like: $max32 = 2147483648; $crc = crc32(884385799717_1_1); if($crc$max32-1) { $crc = $crc-2*$max32; } echo $crc; [2010-02-19 04:20:00] jian at theorchard dot com All I was saying is to point out that crc32 function is unable to return the same result represented in the same way under any different platforms. The documentation does say to use sprintf function to format the result to be an unsigned integer in order to the get same expected result from all platforms. In the real world, we actually do need to use signed checksum in some cases. So with this shortcoming in mind, crc32 function cannot achieve a truly signed checksum purpose. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 User updated by: jian at theorchard dot com Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: On a second thought, however, this still poses an issue. As a programmer, I shouldn't be worreid about all these reformatting and work-arounds. If my function returns me a chicken under development environment, it shouldn't return me an egg once it's released to the production environment. Even though it's the same value, they should also be represented in the same way regardless which platform this function is used. This issue should still be classified as a valid bug in my opinion. Previous Comments: [2010-02-17 22:38:09] jian at theorchard dot com Thanks Derick. That was much more helpful. Unfortunately, I cannot use unsigned integer as our checksum. It has to be signed. I do in fact have a work around function built to solve this issue. I was just wondering whether this will get fixed in the future or not. Since it's a platform dependent issue, it most likely won't get fixed I think. Below is the function I have posted against the crc32 function as a note. I hope this can help others out. Thanks again. function get_signed_int($in) { $int_max = pow(2, 31)-1; if ($in $int_max){ $out = $in - $int_max * 2 - 2; } else { $out = $in; } return $out; } [2010-02-17 22:32:04] der...@php.net Instead of a plain echo, you can also do: printf(%u, crc32(884385799717_1_1)); that should output the same string on every platform (that is at least 32bit). The reason why it is different on Windows vs. (any other) Unix, is because on Windows even on 64 bit CPUs, long (the data type we use for integers) is still only 32bit; on Unices, the long type is usually 64 bit on 64 bit CPUs. [2010-02-17 22:23:29] jian at theorchard dot com I certainly understand that it is the signed output of an unsigned value. But when crc32 function is used for checksum purpose, I'm expecting it to return the same checksum value from under different platforms. Apparently, this unsigned representation of a signed integer as the result of the function call has caused a lot of checksum failures in our applications. I would like this behavior to be fixed in upcoming releases. I wouldn't have created this bug report if I could find my solution or existing reports that you already have. If you can provide me with the bug numbers of the other bug reports you mentioned, I'd be more than happy to study them. Thank you very much. [2010-02-17 18:21:04] paj...@php.net It is the signed output of an unsigned value. The values are correct (there was other bug reports about this, check them to get a more verbose explanation). [2010-02-17 17:47:22] jian at theorchard dot com Description: According to bug# 36306, this issue should have been fixed. But I found it not entirely fixed across all platforms. crc32 is returning an unsigned integer on a 64-bit Linux platform. It does return the signed integer from a 64-bit Windows platform as well as 32-bit Windows/Linux platforms. I found PHP_INT_SIZE and PHP_INT_MAX constants have different values on that 64-bit Linux server with values 8 and 9223372036854775807 respectively. They are 4 and 2147483647 on other 32-bit platforms and 64-bit Windows platform. Reproduce code: --- ? echo crc32(884385799717_1_1) . \n; ? Expected result: I expect to see value -676770709 both on 32-bit and 64-bit platforms. Actual result: -- On 64-bit Linux platform I see 3618196587 On 64-bit Windows platform I see -676770709 On 32-bit platforms I see -676770709 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 Updated by: ras...@php.net Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: It does return the correct set of bits. Anything we do to change what is currently being returned will seriously confuse everyone and the documentation is quite clear on this. Previous Comments: [2010-02-18 08:26:44] jian at theorchard dot com On a second thought, however, this still poses an issue. As a programmer, I shouldn't be worreid about all these reformatting and work-arounds. If my function returns me a chicken under development environment, it shouldn't return me an egg once it's released to the production environment. Even though it's the same value, they should also be represented in the same way regardless which platform this function is used. This issue should still be classified as a valid bug in my opinion. [2010-02-17 22:38:09] jian at theorchard dot com Thanks Derick. That was much more helpful. Unfortunately, I cannot use unsigned integer as our checksum. It has to be signed. I do in fact have a work around function built to solve this issue. I was just wondering whether this will get fixed in the future or not. Since it's a platform dependent issue, it most likely won't get fixed I think. Below is the function I have posted against the crc32 function as a note. I hope this can help others out. Thanks again. function get_signed_int($in) { $int_max = pow(2, 31)-1; if ($in $int_max){ $out = $in - $int_max * 2 - 2; } else { $out = $in; } return $out; } [2010-02-17 22:32:04] der...@php.net Instead of a plain echo, you can also do: printf(%u, crc32(884385799717_1_1)); that should output the same string on every platform (that is at least 32bit). The reason why it is different on Windows vs. (any other) Unix, is because on Windows even on 64 bit CPUs, long (the data type we use for integers) is still only 32bit; on Unices, the long type is usually 64 bit on 64 bit CPUs. [2010-02-17 22:23:29] jian at theorchard dot com I certainly understand that it is the signed output of an unsigned value. But when crc32 function is used for checksum purpose, I'm expecting it to return the same checksum value from under different platforms. Apparently, this unsigned representation of a signed integer as the result of the function call has caused a lot of checksum failures in our applications. I would like this behavior to be fixed in upcoming releases. I wouldn't have created this bug report if I could find my solution or existing reports that you already have. If you can provide me with the bug numbers of the other bug reports you mentioned, I'd be more than happy to study them. Thank you very much. [2010-02-17 18:21:04] paj...@php.net It is the signed output of an unsigned value. The values are correct (there was other bug reports about this, check them to get a more verbose explanation). The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 User updated by: jian at theorchard dot com Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: All I was saying is to point out that crc32 function is unable to return the same result represented in the same way under any different platforms. The documentation does say to use sprintf function to format the result to be an unsigned integer in order to the get same expected result from all platforms. In the real world, we actually do need to use signed checksum in some cases. So with this shortcoming in mind, crc32 function cannot achieve a truly signed checksum purpose. Previous Comments: [2010-02-18 08:34:59] ras...@php.net It does return the correct set of bits. Anything we do to change what is currently being returned will seriously confuse everyone and the documentation is quite clear on this. [2010-02-18 08:26:44] jian at theorchard dot com On a second thought, however, this still poses an issue. As a programmer, I shouldn't be worreid about all these reformatting and work-arounds. If my function returns me a chicken under development environment, it shouldn't return me an egg once it's released to the production environment. Even though it's the same value, they should also be represented in the same way regardless which platform this function is used. This issue should still be classified as a valid bug in my opinion. [2010-02-17 22:38:09] jian at theorchard dot com Thanks Derick. That was much more helpful. Unfortunately, I cannot use unsigned integer as our checksum. It has to be signed. I do in fact have a work around function built to solve this issue. I was just wondering whether this will get fixed in the future or not. Since it's a platform dependent issue, it most likely won't get fixed I think. Below is the function I have posted against the crc32 function as a note. I hope this can help others out. Thanks again. function get_signed_int($in) { $int_max = pow(2, 31)-1; if ($in $int_max){ $out = $in - $int_max * 2 - 2; } else { $out = $in; } return $out; } [2010-02-17 22:32:04] der...@php.net Instead of a plain echo, you can also do: printf(%u, crc32(884385799717_1_1)); that should output the same string on every platform (that is at least 32bit). The reason why it is different on Windows vs. (any other) Unix, is because on Windows even on 64 bit CPUs, long (the data type we use for integers) is still only 32bit; on Unices, the long type is usually 64 bit on 64 bit CPUs. [2010-02-17 22:23:29] jian at theorchard dot com I certainly understand that it is the signed output of an unsigned value. But when crc32 function is used for checksum purpose, I'm expecting it to return the same checksum value from under different platforms. Apparently, this unsigned representation of a signed integer as the result of the function call has caused a lot of checksum failures in our applications. I would like this behavior to be fixed in upcoming releases. I wouldn't have created this bug report if I could find my solution or existing reports that you already have. If you can provide me with the bug numbers of the other bug reports you mentioned, I'd be more than happy to study them. Thank you very much. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 Updated by: ras...@php.net Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: Why can't you always use a signed checksum if that is what you want? crc32 simply returns 32 bits. You always get the same 32 bits regardless of the platform. If you want to always represent that as a signed 32-bit integer, then do so. The fact that some platforms have the ability to show those 32 bits without messing up the sign is irrelevant. Just emulate it with something stupidly simple like: $max32 = 2147483648; $crc = crc32(884385799717_1_1); if($crc$max32-1) { $crc = $crc-2*$max32; } echo $crc; Previous Comments: [2010-02-19 04:20:00] jian at theorchard dot com All I was saying is to point out that crc32 function is unable to return the same result represented in the same way under any different platforms. The documentation does say to use sprintf function to format the result to be an unsigned integer in order to the get same expected result from all platforms. In the real world, we actually do need to use signed checksum in some cases. So with this shortcoming in mind, crc32 function cannot achieve a truly signed checksum purpose. [2010-02-18 08:34:59] ras...@php.net It does return the correct set of bits. Anything we do to change what is currently being returned will seriously confuse everyone and the documentation is quite clear on this. [2010-02-18 08:26:44] jian at theorchard dot com On a second thought, however, this still poses an issue. As a programmer, I shouldn't be worreid about all these reformatting and work-arounds. If my function returns me a chicken under development environment, it shouldn't return me an egg once it's released to the production environment. Even though it's the same value, they should also be represented in the same way regardless which platform this function is used. This issue should still be classified as a valid bug in my opinion. [2010-02-17 22:38:09] jian at theorchard dot com Thanks Derick. That was much more helpful. Unfortunately, I cannot use unsigned integer as our checksum. It has to be signed. I do in fact have a work around function built to solve this issue. I was just wondering whether this will get fixed in the future or not. Since it's a platform dependent issue, it most likely won't get fixed I think. Below is the function I have posted against the crc32 function as a note. I hope this can help others out. Thanks again. function get_signed_int($in) { $int_max = pow(2, 31)-1; if ($in $int_max){ $out = $in - $int_max * 2 - 2; } else { $out = $in; } return $out; } [2010-02-17 22:32:04] der...@php.net Instead of a plain echo, you can also do: printf(%u, crc32(884385799717_1_1)); that should output the same string on every platform (that is at least 32bit). The reason why it is different on Windows vs. (any other) Unix, is because on Windows even on 64 bit CPUs, long (the data type we use for integers) is still only 32bit; on Unices, the long type is usually 64 bit on 64 bit CPUs. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/51073 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 User updated by: jian at theorchard dot com Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: I certainly understand that it is the signed output of an unsigned value. But when crc32 function is used for checksum purpose, I'm expecting it to return the same checksum value from under different platforms. Apparently, this unsigned representation of a signed integer as the result of the function call has caused a lot of checksum failures in our applications. I would like this behavior to be fixed in upcoming releases. I wouldn't have created this bug report if I could find my solution or existing reports that you already have. If you can provide me with the bug numbers of the other bug reports you mentioned, I'd be more than happy to study them. Thank you very much. Previous Comments: [2010-02-17 18:21:04] paj...@php.net It is the signed output of an unsigned value. The values are correct (there was other bug reports about this, check them to get a more verbose explanation). [2010-02-17 17:47:22] jian at theorchard dot com Description: According to bug# 36306, this issue should have been fixed. But I found it not entirely fixed across all platforms. crc32 is returning an unsigned integer on a 64-bit Linux platform. It does return the signed integer from a 64-bit Windows platform as well as 32-bit Windows/Linux platforms. I found PHP_INT_SIZE and PHP_INT_MAX constants have different values on that 64-bit Linux server with values 8 and 9223372036854775807 respectively. They are 4 and 2147483647 on other 32-bit platforms and 64-bit Windows platform. Reproduce code: --- ? echo crc32(884385799717_1_1) . \n; ? Expected result: I expect to see value -676770709 both on 32-bit and 64-bit platforms. Actual result: -- On 64-bit Linux platform I see 3618196587 On 64-bit Windows platform I see -676770709 On 32-bit platforms I see -676770709 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 Updated by: der...@php.net Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: Instead of a plain echo, you can also do: printf(%u, crc32(884385799717_1_1)); that should output the same string on every platform (that is at least 32bit). The reason why it is different on Windows vs. (any other) Unix, is because on Windows even on 64 bit CPUs, long (the data type we use for integers) is still only 32bit; on Unices, the long type is usually 64 bit on 64 bit CPUs. Previous Comments: [2010-02-17 22:23:29] jian at theorchard dot com I certainly understand that it is the signed output of an unsigned value. But when crc32 function is used for checksum purpose, I'm expecting it to return the same checksum value from under different platforms. Apparently, this unsigned representation of a signed integer as the result of the function call has caused a lot of checksum failures in our applications. I would like this behavior to be fixed in upcoming releases. I wouldn't have created this bug report if I could find my solution or existing reports that you already have. If you can provide me with the bug numbers of the other bug reports you mentioned, I'd be more than happy to study them. Thank you very much. [2010-02-17 18:21:04] paj...@php.net It is the signed output of an unsigned value. The values are correct (there was other bug reports about this, check them to get a more verbose explanation). [2010-02-17 17:47:22] jian at theorchard dot com Description: According to bug# 36306, this issue should have been fixed. But I found it not entirely fixed across all platforms. crc32 is returning an unsigned integer on a 64-bit Linux platform. It does return the signed integer from a 64-bit Windows platform as well as 32-bit Windows/Linux platforms. I found PHP_INT_SIZE and PHP_INT_MAX constants have different values on that 64-bit Linux server with values 8 and 9223372036854775807 respectively. They are 4 and 2147483647 on other 32-bit platforms and 64-bit Windows platform. Reproduce code: --- ? echo crc32(884385799717_1_1) . \n; ? Expected result: I expect to see value -676770709 both on 32-bit and 64-bit platforms. Actual result: -- On 64-bit Linux platform I see 3618196587 On 64-bit Windows platform I see -676770709 On 32-bit platforms I see -676770709 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1
#51073 [Bgs]: crc32() function result differs on 64-bit Linux platforms and others
ID: 51073 User updated by: jian at theorchard dot com Reported By: jian at theorchard dot com Status: Bogus Bug Type: Feature/Change Request Operating System: Linux RHEL 5 PHP Version: 5.3.1 New Comment: Thanks Derick. That was much more helpful. Unfortunately, I cannot use unsigned integer as our checksum. It has to be signed. I do in fact have a work around function built to solve this issue. I was just wondering whether this will get fixed in the future or not. Since it's a platform dependent issue, it most likely won't get fixed I think. Below is the function I have posted against the crc32 function as a note. I hope this can help others out. Thanks again. function get_signed_int($in) { $int_max = pow(2, 31)-1; if ($in $int_max){ $out = $in - $int_max * 2 - 2; } else { $out = $in; } return $out; } Previous Comments: [2010-02-17 22:32:04] der...@php.net Instead of a plain echo, you can also do: printf(%u, crc32(884385799717_1_1)); that should output the same string on every platform (that is at least 32bit). The reason why it is different on Windows vs. (any other) Unix, is because on Windows even on 64 bit CPUs, long (the data type we use for integers) is still only 32bit; on Unices, the long type is usually 64 bit on 64 bit CPUs. [2010-02-17 22:23:29] jian at theorchard dot com I certainly understand that it is the signed output of an unsigned value. But when crc32 function is used for checksum purpose, I'm expecting it to return the same checksum value from under different platforms. Apparently, this unsigned representation of a signed integer as the result of the function call has caused a lot of checksum failures in our applications. I would like this behavior to be fixed in upcoming releases. I wouldn't have created this bug report if I could find my solution or existing reports that you already have. If you can provide me with the bug numbers of the other bug reports you mentioned, I'd be more than happy to study them. Thank you very much. [2010-02-17 18:21:04] paj...@php.net It is the signed output of an unsigned value. The values are correct (there was other bug reports about this, check them to get a more verbose explanation). [2010-02-17 17:47:22] jian at theorchard dot com Description: According to bug# 36306, this issue should have been fixed. But I found it not entirely fixed across all platforms. crc32 is returning an unsigned integer on a 64-bit Linux platform. It does return the signed integer from a 64-bit Windows platform as well as 32-bit Windows/Linux platforms. I found PHP_INT_SIZE and PHP_INT_MAX constants have different values on that 64-bit Linux server with values 8 and 9223372036854775807 respectively. They are 4 and 2147483647 on other 32-bit platforms and 64-bit Windows platform. Reproduce code: --- ? echo crc32(884385799717_1_1) . \n; ? Expected result: I expect to see value -676770709 both on 32-bit and 64-bit platforms. Actual result: -- On 64-bit Linux platform I see 3618196587 On 64-bit Windows platform I see -676770709 On 32-bit platforms I see -676770709 -- Edit this bug report at http://bugs.php.net/?id=51073edit=1