Skip to content

Commit

Permalink
Fix/memory layout assumptions (#185)
Browse files Browse the repository at this point in the history
* Don't assume index is just before data
* release notes
  • Loading branch information
DanEngelbrecht authored Apr 11, 2022
1 parent 8b4f7c4 commit 4aae978
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ jobs:
# Changes in this Release
- **FIX** Fix memory and handle leak when encountering empty folders
- **FIX** Fix reallocation size when scanning folders
- **FIX** Don't assume index is just before data
draft: false
prerelease: false
files: "*-x64.zip"
16 changes: 8 additions & 8 deletions src/longtail.c
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ int Longtail_WriteVersionIndexToBuffer(
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "Longtail_Alloc() failed with %d", ENOMEM)
return ENOMEM;
}
memcpy(*out_buffer, &version_index[1], index_data_size);
memcpy(*out_buffer, version_index->m_Version, index_data_size);
*out_size = index_data_size;
return 0;
}
Expand Down Expand Up @@ -2741,7 +2741,7 @@ int Longtail_WriteVersionIndex(
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "storage_api->OpenWriteFile) failed with %d",err)
return err;
}
err = storage_api->Write(storage_api, file_handle, 0, index_data_size, &version_index[1]);
err = storage_api->Write(storage_api, file_handle, 0, index_data_size, version_index->m_Version);
if (err)
{
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "storage_api->Write() failed with %d", err)
Expand Down Expand Up @@ -3062,7 +3062,7 @@ int Longtail_WriteBlockIndexToBuffer(
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "Longtail_Alloc() failed with %d", ENOMEM)
return ENOMEM;
}
memcpy(*out_buffer, &block_index[1], index_data_size);
memcpy(*out_buffer, block_index->m_BlockHash, index_data_size);
*out_size = index_data_size;
return 0;
}
Expand Down Expand Up @@ -3138,7 +3138,7 @@ int Longtail_WriteBlockIndex(
return err;
}
size_t index_data_size = Longtail_GetBlockIndexDataSize(*block_index->m_ChunkCount);
err = storage_api->Write(storage_api, file_handle, 0, index_data_size, &block_index[1]);
err = storage_api->Write(storage_api, file_handle, 0, index_data_size, block_index->m_BlockHash);
if (err){
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "storage_api->Write() failed with %d", err)
storage_api->CloseFile(storage_api, file_handle);
Expand Down Expand Up @@ -3402,7 +3402,7 @@ int Longtail_WriteStoredBlockToBuffer(
}
uint8_t* write_ptr = (uint8_t*)mem;

memcpy(write_ptr, &stored_block->m_BlockIndex[1], block_index_data_size);
memcpy(write_ptr, stored_block->m_BlockIndex->m_BlockHash, block_index_data_size);
write_ptr += block_index_data_size;
memcpy(write_ptr, stored_block->m_BlockData, stored_block->m_BlockChunksDataSize);

Expand Down Expand Up @@ -3482,7 +3482,7 @@ int Longtail_WriteStoredBlock(
uint32_t write_offset = 0;
uint32_t chunk_count = *stored_block->m_BlockIndex->m_ChunkCount;
uint32_t block_index_data_size = (uint32_t)Longtail_GetBlockIndexDataSize(chunk_count);
err = storage_api->Write(storage_api, block_file_handle, write_offset, block_index_data_size, &stored_block->m_BlockIndex[1]);
err = storage_api->Write(storage_api, block_file_handle, write_offset, block_index_data_size, stored_block->m_BlockIndex->m_BlockHash);
if (err)
{
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "storage_api->Write() failed with %d", err)
Expand Down Expand Up @@ -7919,7 +7919,7 @@ int Longtail_WriteStoreIndexToBuffer(
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "Longtail_GetStoreIndexDataSize() failed with %d", ENOMEM)
return ENOMEM;
}
memcpy(*out_buffer, &store_index[1], index_data_size);
memcpy(*out_buffer, store_index->m_Version, index_data_size);
*out_size = index_data_size;
return 0;
}
Expand Down Expand Up @@ -7954,7 +7954,7 @@ int Longtail_WriteStoreIndex(
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "storage_api->OpenWriteFile() failed with %d", err)
return err;
}
err = storage_api->Write(storage_api, file_handle, 0, index_data_size, &store_index[1]);
err = storage_api->Write(storage_api, file_handle, 0, index_data_size, store_index->m_Version);
if (err)
{
LONGTAIL_LOG(ctx, LONGTAIL_LOG_LEVEL_ERROR, "storage_api->Write() failed with %d", err)
Expand Down

0 comments on commit 4aae978

Please sign in to comment.