ajbdev / phpsc2replay

Automatically exported from code.google.com/p/phpsc2replay
0 stars 1 forks source link

Error in Parsing #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Upload through upload_file.php on 64-bit Linux with php v5.2.9 

What is the expected output? What do you see instead?
Should extract file data but all fail with error message similar to "Error 
reading the replay.details file". 

What version of the product are you using? On what operating system?
Current on Linux x86_64 with php 5.2.9.  

Please provide any additional information below.
I ran this fine on a local server with Windows Vista 64 and php 5.2.13.  In 
doing some debugging I traced the variation down to the results of

$temp1 = ($seed & 0xFFFF) << 0x10;

in the function initCryptTable.  

e.g for a $seed value of 2143124 the vista install returns $temp1 value of 
-1282146304 while linux 64 returns 3012820992.   

Is this due to the problem of php being unable to handle unsigned integers over 
2^31?  It seems to me that the Linuc machine actually hadled the shift 
correctly while the Vista machine returned a signed integer result but the 
Vista machine is extracting file data without a problem?

Original issue reported on code.google.com by onndr...@gmail.com on 11 Jun 2010 at 5:22

GoogleCodeExporter commented 8 years ago
did some testing on PHP_INT_MAX and it's 2147483647 on the windows machine and 
9223372036854775807 on the linux ... the numbers where there is a variation in 
$temp1 appear to be > 2147483647

Original comment by onndr...@gmail.com on 11 Jun 2010 at 7:18

GoogleCodeExporter commented 8 years ago
To continue the debugging investigation:

On the Vista 64 machine numbers handle normally until they reach 2^31 
(2147483648).  At this value they flip sign and increment from -2^31 (so 2^31 + 
x) becomes -(2^31) + x.  Numbers continue incrementing in this manner until 3 * 
2^31 when they flip to -2^31 again.

The routines you adapted for reading the MoPaC archives were originally written 
for unsigned 32bit integers which should be equivalent to how they are handled 
on the Linux machine but the code appears to break when they are handled this 
way.  There are numerous points in the code that can generate values above 2^31 
and trigger this difference.

Original comment by onndr...@gmail.com on 11 Jun 2010 at 1:09

GoogleCodeExporter commented 8 years ago
PHP does not support unsigned values at all. As an extra bonus, if an int 
happens to overflow, it gets automagically converted to a float, which 
immediately breaks all bitwise operations. However, since the unsigned numbers 
are stored in two's complement format, simple arithmetic works regardless of 
the value PHP prints(as per your example -1282146304 and 3012820992 have the 
exact same bit representations). The uPlus function is there to prevent integer 
overflows that would happen if one just used '+'. Same thing with hacks like 

$seed = ((0xEEEE << 16) | 0xEEEE);

If one simply used $seed = 0xEEEEEEEE, it would overflow and be represented as 
a float. Bitwise operations discard the extra bits and do not cause an overflow.

Now as for the actual problem, since bitwise operations(mainly left shift) in a 
64-bit system don't overflow after 32 bits, it may be that they get carried 
down to a subsequent right shift. It may also be an endianness issue, which 
would be bloody annoying. I added some debugging code to the MPQFile class to 
print out the hash and block tables, please see if they match up with the ones 
on your vista system and include the results here.

Original comment by lauri.vi...@gmail.com on 11 Jun 2010 at 10:05

GoogleCodeExporter commented 8 years ago
They don't match ....

Vista debug:

DEBUG: Hash table
HashA, HashB, Language+platform, Fileblockindex

D38437CB 07DFEAEC 00000000 00000008

AAC2A54B F4762B95 00000000 00000002

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

C9E5B770 3B18F6B6 00000000 00000004

5A7E8BDC FF253F5C 00000000 00000001

3B2B1EA0 B72EF057 00000000 00000005

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FD657910 4E9B98A7 00000000 00000007

D383C29C EF402E92 00000000 00000000

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

1DA8B0CF A2CEFF28 00000000 00000006

31952289 6A5FFAA3 00000000 00000003

DEBUG: Block table
Offset, Blocksize, Filesize, flags

0000042C      515     1325 81000200

0000062F      489     1127 81000200

00000818    20490    60459 84000200

00005822       82      124 81000200

00005874    35781    49756 84000200

0000E439     1246     2518 81000200

0000E917      221      528 81000200

0000E9F4       82      146 81000200

0000EA46      173      260 81000200

Linux Debug:

DEBUG: Hash table
HashA, HashB, Language+platform, Fileblockindex

D38437CB 07DFEAEC FFFFFFFF00000000 FFFFFFFF00000008

FFFFFFFFAAC2A54B FFFFFFFFF4762B95 FFFFFFFF00000000 FFFFFFFF00000002

FFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFF FFFFFFFFFFFFFFFF

FFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF

FFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFF FFFFFFFF

C9E5B770 FFFFFFFF3B18F6B6 00000000 00000004

FFFFFFFF5A7E8BDC FF253F5C FFFFFFFF00000000 FFFFFFFF00000001

3B2B1EA0 B72EF057 FFFFFFFF00000000 FFFFFFFF00000005

FFFFFFFF FFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF

FD657910 4E9B98A7 00000000 FFFFFFFF00000007

FFFFFFFFD383C29C FFFFFFFFEF402E92 00000000 00000000

FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF

FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FFFFFFFFFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF

FFFFFFFF1DA8B0CF FFFFFFFFA2CEFF28 FFFFFFFF00000000 00000006

FFFFFFFF31952289 6A5FFAA3 FFFFFFFF00000000 FFFFFFFF00000003

DEBUG: Block table
Offset, Blocksize, Filesize, flags

0000042C -4294966781 -4294965971 FFFFFFFF81000200

FFFFFFFF0000062F      489     1127 81000200

FFFFFFFF00000818    20490 -4294906837 84000200

FFFFFFFF00005822       82 -4294967172 FFFFFFFF81000200

00005874 -4294931515 -4294917540 FFFFFFFF84000200

0000E439     1246 -4294964778 FFFFFFFF81000200

0000E917 -4294967075 -4294966768 81000200

0000E9F4 -4294967214      146 81000200

FFFFFFFF0000EA46      173      260 FFFFFFFF81000200

Original comment by onndr...@gmail.com on 12 Jun 2010 at 12:39

GoogleCodeExporter commented 8 years ago
I've added a simple fix(drop everything but the low 32 bits), see if the newest 
files work any better.

Original comment by lauri.vi...@gmail.com on 12 Jun 2010 at 8:48

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
That seems to have fixed it

Original comment by onndr...@gmail.com on 12 Jun 2010 at 9:18

GoogleCodeExporter commented 8 years ago

Original comment by lauri.vi...@gmail.com on 12 Jun 2010 at 9:27