Fixing bug in fmt3 patching routine
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2025-04-28 17:06:06 +03:00
parent 2b0d2e0a4f
commit 7b9e1764d9
1 changed files with 7 additions and 5 deletions

View File

@ -458,18 +458,20 @@ function _config_patch_bundle_fmt3(
$chunk_entries = array_filter($header, fn($item) => $item[4] == $chunk_offset);
//chunk contains only one patch entry
$patched_chunk = lz4_compress($patch_payload, 9);
if(strlen($patched_chunk) > $max_chunk_size)
$max_chunk_size = strlen($patched_chunk);
$patch_payload_lz4 = lz4_compress($patch_payload, 9);
$patched_chunk = pack("V", strlen($patch_payload_lz4));
$patched_chunk .= $patch_payload_lz4;
if(strlen($patch_payload) > $max_chunk_size)
$max_chunk_size = strlen($patch_payload);
//TODO: make a better generic algorithm for patching the whole chunk
//special case for single entry
if(count($chunk_entries) == 1 && $payloads_offset == 0)
{
$lz4_chunk_size = unpack("V", substr($packed_data, $chunk_offset, 4))[1];
$lz4_chunk_size = unpack("V", substr($payloads_bundle, $chunk_offset, 4))[1];
//we can just replace chunk in place if the size of a patched chunk is less or equal
if(strlen($patched_chunk) <= $lz4_chunk_size)
if(strlen($patch_payload_lz4) <= $lz4_chunk_size)
{
$payloads_bundle = substr_replace($payloads_bundle, $patched_chunk, $chunk_offset, strlen($patched_chunk));
$header_entry[6] = strlen($patch_payload);