Skip to content

Read only up to MaxSize for VMDK header#2

Merged
Olof-Lagerkvist merged 1 commit into
LTRData:LTRData.DiscUtils-initialfrom
Rainmaker52:LTRData.DiscUtils-initial
Jun 28, 2023
Merged

Read only up to MaxSize for VMDK header#2
Olof-Lagerkvist merged 1 commit into
LTRData:LTRData.DiscUtils-initialfrom
Rainmaker52:LTRData.DiscUtils-initial

Conversation

@Rainmaker52

Copy link
Copy Markdown

While handling an untrusted stream, in the old implementation, the StreamReader.ReadLine() would block until it encountered an EOL character.

In my case, a faulty NFS client caused all bytes to be read as 0. This caused the program to fill up the entire memory while reading a large VMDK.

This implementation reads only the bytes up to MaxSize. It also:

…reamReader.ReadLine() would block until it encountered an EOL character.

In my case, a faulty NFS client caused all bytes to be read as 0. This caused the program to fill up the entire memory while reading a large VMDK.

This implementation reads only the bytes up to MaxSize. It also:
- Uses UTF-8 encoding, instead of ASCII
- Performs case insensitive searches.
This is based upon the "standard" defined here:
https://github.com/libyal/libvmdk/blob/main/documentation/VMWare%20Virtual%20Disk%20Format%20(VMDK).asciidoc
@Olof-Lagerkvist
Olof-Lagerkvist merged commit 4cd3dac into LTRData:LTRData.DiscUtils-initial Jun 28, 2023
@Olof-Lagerkvist

Copy link
Copy Markdown
Member

Thanks a lot for this! Just made some minor changes, try/finally around the ArrayPool Rent/Return to avoid memory leak in case of exceptions and also changed Encoding.UTF8.GetString to only use actual number of read bytes in the array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants