Skip to content

Commit 050ea91

Browse files
committed
OrcLib: MftRecordAttribute: fix WOF for resident attribute
1 parent ecd4fb1 commit 050ea91

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

src/OrcLib/MftRecordAttribute.cpp

+43-13
Original file line numberDiff line numberDiff line change
@@ -885,30 +885,60 @@ HRESULT WOFReparseAttribute::GetStreams(
885885
return E_FAIL;
886886
}
887887

888-
auto ntfsStream = make_shared<NTFSStream>();
889-
HRESULT hr = ntfsStream->OpenAllocatedDataStream(pVolReader, wofAttribute);
890-
if (FAILED(hr))
888+
if (wofAttribute->IsResident())
891889
{
892-
Log::Error(L"Failed to open NTFSStream [{}]", SystemError(hr));
893-
return hr;
890+
auto bufferStream = make_shared<BufferStream<2048>>();
891+
HRESULT hr = bufferStream->Open();
892+
if (FAILED(hr))
893+
{
894+
return hr;
895+
}
896+
897+
ULONGLONG ullBytesWritten = 0LL;
898+
hr = bufferStream->Write(
899+
((PBYTE)wofAttribute->Header()) + wofAttribute->Header()->Form.Resident.ValueOffset,
900+
wofAttribute->Header()->Form.Resident.ValueLength,
901+
&ullBytesWritten);
902+
if (FAILED(hr))
903+
{
904+
return hr;
905+
}
906+
907+
if (ullBytesWritten != wofAttribute->Header()->Form.Resident.ValueLength)
908+
{
909+
return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
910+
}
911+
912+
rawStream = bufferStream;
894913
}
914+
else
915+
{
916+
auto stream = make_shared<NTFSStream>();
917+
HRESULT hr = stream->OpenAllocatedDataStream(pVolReader, wofAttribute);
918+
if (FAILED(hr))
919+
{
920+
Log::Error(L"Failed to open NTFSStream [{}]", SystemError(hr));
921+
return hr;
922+
}
895923

896-
// Nonresident: checked in '::GetWofDataAttribute()'
897-
Log::Debug(
898-
"Open WOF stream (algorithm: {}, compressed size: {} uncompressed size: {})",
899-
ToString(m_algorithm),
900-
ntfsStream->GetSize(),
901-
dataAttribute->Header()->Form.Nonresident.FileSize);
924+
// Nonresident: checked in '::GetWofDataAttribute()'
925+
Log::Debug(
926+
"Open WOF stream (algorithm: {}, compressed size: {} uncompressed size: {})",
927+
ToString(m_algorithm),
928+
stream->GetSize(),
929+
dataAttribute->Header()->Form.Nonresident.FileSize);
930+
931+
rawStream = stream;
932+
}
902933

903934
auto wofStream = make_shared<UncompressWofStream>();
904-
hr = wofStream->Open(ntfsStream, m_algorithm, dataAttribute->Header()->Form.Nonresident.FileSize);
935+
HRESULT hr = wofStream->Open(rawStream, m_algorithm, dataAttribute->Header()->Form.Nonresident.FileSize);
905936
if (FAILED(hr))
906937
{
907938
Log::Debug("Failed to open wof stream [{}]", SystemError(hr));
908939
return hr;
909940
}
910941

911-
rawStream = ntfsStream;
912942
dataStream = wofStream;
913943
return S_OK;
914944
}

0 commit comments

Comments
 (0)