diff --git a/CHANGELOG.md b/CHANGELOG.md index e37f803..91783f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,10 @@ This update introduces minor bug fixes. - Fixed issue where all development dependencies were not correctly being added to debug builds in composer projects, instead these dependencies were added globally to the build configuration. This issue was fixed by adding all the development dependencies to the debug build configurations only. + - Fixed issue when creating a shadow copy of a package, if the universe aligns together and the cosmos unit together to + produce a package length exactly to where the end-of-package byte sequence is cut in half, the shadow copy will fail + to be created due to the end-of-package byte sequence being cut in half, this issue was fixed by reading the package + in chunks to determine the end-of-package byte sequence. ## [2.0.3] - 2023-10-17 diff --git a/src/ncc/Classes/PackageReader.php b/src/ncc/Classes/PackageReader.php index 814f253..3a887c4 100644 --- a/src/ncc/Classes/PackageReader.php +++ b/src/ncc/Classes/PackageReader.php @@ -182,17 +182,28 @@ // Seek the data until the end of the package (FF AA 55 F0) fseek($this->package_file, $this->data_offset); + $buffer = ''; while(!feof($this->package_file)) { - $buffer = fread($this->package_file, 1024); - $this->data_length += strlen($buffer); + $current_chunk = fread($this->package_file, 1024); + $this->data_length += strlen($current_chunk); + $buffer .= $current_chunk; + // If we detect the end-of-data byte sequence if (($position = strpos($buffer, "\xFF\xAA\x55\xF0")) !== false) { $this->data_length -= strlen($buffer) - $position; $this->package_length += $this->data_length + 4; break; } + + // Check if the buffer is 1MB or larger + if(strlen($buffer) > 1048576) + { + // Remove the first 512kb of the buffer + $buffer = substr($buffer, 512000); + } + } if($this->data_length === null || $this->data_length === 0)