Validate the DXBC shader length against the container part size - #8782
Open
Nilesh Patil (nileshpatil6) wants to merge 1 commit into
Open
Validate the DXBC shader length against the container part size#8782Nilesh Patil (nileshpatil6) wants to merge 1 commit into
Nilesh Patil (nileshpatil6) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Towards #8406.
CShaderCodeParser::SetShadertakes the shader's length in tokens frompBuffer[1]and derives its end pointer from it:m_pShaderEndToken = pBuffer + pBuffer[1];so a wrong length there sends the parser off the end of the buffer.
SetShaderitself has no size to check against, so the bound has to come from the caller.Of the two call paths,
ConvertInDriverImplhas no buffer size at all: the driver hands over a bareconst UINT32*and the declared length is the only length there is. It already rejects the degenerate case withIFTBOOL(SizeInUINTs >= 2, ...), and without an API change there is nothing more it can check.ConvertImplis the one that does have a size, and was not using it.DxilContainerReader::GetPartContenthas an optional out parameter for the part size:and the call here passed only two arguments, so the part size was discarded. The container reader bounds the part within the container, but nothing then checked that the shader's own declared length fits inside that part, so a part whose length token is too large still walked the parser past the end.
This asks for the size and checks two things before the buffer reaches the parser: that the part is big enough to hold the version and length tokens that
SetShaderreads, and that the declared length stays within the part. The comparison is written as a division so there is no multiplication to overflow. BothSetShadercalls inConvertImpltake the same buffer, so the single check covers both.Two notes:
ConvertInDriverImplalone for the reason above. If you would rather have the bound enforced inside the parser, that needs a size parameter onSetShaderand a matching change to the driver entry point, which is a larger API question than I wanted to decide in this PR. Happy to follow up with that shape if you prefer it.projects/dxilconv/CMakeLists.txtis gated onif(WIN32)and I do not have MSVC on this machine, so my Linux build of the repo does not produce the target. I checked the pieces against the headers instead: the three-argumentGetPartContentoverload above,DXC_E_ERROR_PARSING_DXBC_BYTECODEininclude/dxc/Support/ErrorCodes.h(already used a few lines away inConvertInDriverImpl), andCShaderTokenbeingtypedef UINTinShaderBinary.h. Please let CI confirm the build.