Skip to content

Commit

Permalink
Fix crash when mounting btrfs volumes
Browse files Browse the repository at this point in the history
Found item has data offset higher than block size. Move the stream to get the
data. If the data does not fit in the block, fetch it directly from the device.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Fixes #12788.
  • Loading branch information
hyche authored and pulkomandy committed Mar 13, 2017
1 parent 4135f1f commit 3f73d56
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/add-ons/kernel/file_systems/btrfs/BPlusTree.cpp
Expand Up @@ -168,10 +168,22 @@ BPlusTree::_Find(struct btrfs_key &key, void** _value, size_t* _size,
stream->entries[i].Offset(), stream->entries[i].Size());
if (_value != NULL) {
*_value = malloc(stream->entries[i].Size());
memcpy(*_value, ((uint8 *)&stream->entries[0]
+ stream->entries[i].Offset()),
stream->entries[i].Size());
uint32 totalOffset = stream->entries[i].Offset() + sizeof(btrfs_header);
key.SetOffset(stream->entries[i].key.Offset());

if ((fVolume->BlockSize() - totalOffset % fVolume->BlockSize())
>= stream->entries[i].Size()) {
//If there is enough space for *_value
stream = (btrfs_stream*)cached.SetTo(physical
+ totalOffset / fVolume->BlockSize());
memcpy(*_value, ((uint8 *)&stream->header
+ totalOffset % fVolume->BlockSize()),
stream->entries[i].Size());
} else {
read_pos(fVolume->Device(), physical
* fVolume->BlockSize() + totalOffset,
*_value, stream->entries[i].Size());
}
if (_size != NULL)
*_size = stream->entries[i].Size();
}
Expand Down

0 comments on commit 3f73d56

Please sign in to comment.