peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.38k stars 203 forks source link

file resource is not flushed by itself by GC #851

Open miou-gh opened 4 years ago

miou-gh commented 4 years ago

The following snippet produces a discrepancy between PHP and PeachPie. It appears that the IL generated by PeachPie does not seek and write the bytes at the appropriate location. Instead, it appears to do nothing at all.

PHP: 0x45 0x49 0x46 0x75 0xBB 0x73 0xED PeachPie: 0x45 0x49 0x46 0x00 0x00 0x00 0x00

$filename = "output.txt";
$fh = fopen($filename, 'wb');

fwrite($fh, "EIF", 3);
fwrite($fh, "\x0\x0\x0\x0");

fflush($fh);
$rid = crc32(file_get_contents($filename)) | 0x01010101;
fseek($fh, 3, SEEK_SET);
fwrite($fh, pack('n', ($rid >> 16) & 0xFFFF) . pack('n', $rid & 0xFFFF), 4);
jakubmisek commented 4 years ago

thanks for the issue. It seems for now, PeachPie needs an additional fflush at the end, since it won't close the file handle automatically

fflush($fh);