Skip to content

Commit

Permalink
Fix version number and thus uuid in stripped snapshots. (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Mar 20, 2023
1 parent 6a7be0b commit f4eb7fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/ar.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ class MemoryReader {
MemoryReader(uint8* buffer, int size) : buffer_(buffer), size_(size) {}

/// Fills the next file.
/// On success, the name of the file is allocated and should be freed with
/// 'free'.
/// On success, the file's name is automatically freed when the 'file'
/// is reused or the destructor is called.
/// On success, the content of the file is pointing directly into the memory
/// that was given at construction.
///
///
/// Returns 0 when a file was successfully read.
///
/// Returns [AR_END_OF_ARCHIVE] when at the end of the archive.
Expand Down Expand Up @@ -221,7 +220,8 @@ class FileReader {
///
/// Returns 0 when a file was successfully read.
/// In this case:
/// - The name of the file is allocated and should be freed with 'free'.
/// - The name of the file is automatically freed when the 'file' is
/// reused or its destructor is called.
/// - The content of the file is allocated and should be freed with 'free'.
///
/// Returns [AR_END_OF_ARCHIVE] when at the end of the archive.
Expand All @@ -238,6 +238,9 @@ class FileReader {
/// If [reset] is true, starts searching at the beginning of the file. This
/// requires the file to be seekable.
///
/// The name and the content of the result are automatically freed when
/// the file is reused or the destructor is called.
///
/// Returns 0 when a file was successfully read.
/// In that case:
/// - The name of the file is pointing to the given [name].
Expand Down
7 changes: 6 additions & 1 deletion src/snapshot_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ SnapshotBundle SnapshotBundle::stripped() const {
// The const cast should be safe.
snapshot_bytes = List<uint8>(const_cast<uint8*>(file.content()), file.byte_size);
} else if (strcmp(file.name(), SDK_VERSION_NAME) == 0) {
sdk_version = reinterpret_cast<const char*>(file.content());
// Copy the sdk-version so it's null terminated.
int sdk_len = file.byte_size;
char* buffer = unvoid_cast<char*>(malloc(sdk_len + 1));
memcpy(buffer, file.content(), sdk_len);
buffer[sdk_len] = '\0';
sdk_version = buffer;
}
}
return SnapshotBundle(snapshot_bytes, null, null, null, sdk_version);
Expand Down

0 comments on commit f4eb7fb

Please sign in to comment.