File tree Expand file tree Collapse file tree 3 files changed +22
-14
lines changed Expand file tree Collapse file tree 3 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,10 @@ struct RootConstantView : RootParameterView {
160
160
}
161
161
};
162
162
163
+ static Error parseFailed (const Twine &Msg) {
164
+ return make_error<GenericBinaryError>(Msg.str (), object_error::parse_failed);
165
+ }
166
+
163
167
class RootSignature {
164
168
private:
165
169
uint32_t Version = 2 ;
@@ -192,23 +196,25 @@ class RootSignature {
192
196
}
193
197
param_header_iterator param_header_end () { return ParametersHeaders.end (); }
194
198
uint32_t getFlags () const { return Flags; }
195
- RootParameterView
199
+
200
+ llvm::Expected<RootParameterView>
196
201
getParameter (const dxbc::RootParameterHeader &Header) const {
197
202
size_t CorrectOffset = Header.ParameterOffset - ParameterSpaceOffset;
198
203
StringRef Data;
199
204
200
- size_t DataSize = 0 ;
205
+ size_t DataSize;
201
206
202
207
switch (Header.ParameterType ) {
203
208
case dxbc::RootParameterType::Constants32Bit:
204
209
DataSize = sizeof (dxbc::RootConstants);
205
- if (CorrectOffset + DataSize > ParameterSpace.size ()) {
206
- // throw
207
- }
208
- Data = ParameterSpace.substr (CorrectOffset, DataSize);
209
210
break ;
210
211
}
211
212
213
+ if (CorrectOffset + DataSize > ParameterSpace.size ())
214
+ return parseFailed (" Reading structure out of file bounds" );
215
+
216
+ Data = ParameterSpace.substr (CorrectOffset, DataSize);
217
+
212
218
RootParameterView View = RootParameterView (Header, Data);
213
219
return View;
214
220
}
Original file line number Diff line number Diff line change @@ -45,9 +45,13 @@ DXContainerYAML::RootSignatureYamlDesc::RootSignatureYamlDesc(
45
45
NewP.Type = PH.ParameterType ;
46
46
NewP.Visibility = PH.ShaderVisibility ;
47
47
48
- auto ParamView = Data.getParameter (PH);
48
+ llvm::Expected<object::DirectX::RootParameterView> ParamView =
49
+ Data.getParameter (PH);
50
+ if (!ParamView)
51
+ llvm::errs () << " Error: " << ParamView.takeError () << " \n " ;
52
+ auto PV = *ParamView;
49
53
50
- if (auto *RCV = dyn_cast<object::DirectX::RootConstantView>(&ParamView )) {
54
+ if (auto *RCV = dyn_cast<object::DirectX::RootConstantView>(&PV )) {
51
55
auto Constants = RCV->read ();
52
56
if (!Constants)
53
57
llvm::errs () << " Error: " << Constants.takeError () << " \n " ;
Original file line number Diff line number Diff line change @@ -926,9 +926,10 @@ TEST(RootSignature, ParseRootConstant) {
926
926
ASSERT_EQ ((unsigned )RootParam.ParameterType , 1u );
927
927
ASSERT_EQ ((unsigned )RootParam.ShaderVisibility , 2u );
928
928
auto ParamView = RS.getParameter (RootParam);
929
+ ASSERT_THAT_ERROR (ParamView.takeError (), Succeeded ());
929
930
930
931
DirectX::RootConstantView *RootConstantsView =
931
- dyn_cast<DirectX::RootConstantView>(&ParamView);
932
+ dyn_cast<DirectX::RootConstantView>(&* ParamView);
932
933
ASSERT_TRUE (RootConstantsView != nullptr );
933
934
auto Constants = RootConstantsView->read ();
934
935
@@ -999,11 +1000,8 @@ TEST(RootSignature, ParseRootConstant) {
999
1000
const auto &RS = MaybeRS.value ();
1000
1001
auto RootParam = *RS.param_header ().begin ();
1001
1002
auto ParamView = RS.getParameter (RootParam);
1002
- DirectX::RootConstantView *RootConstantsView =
1003
- dyn_cast<DirectX::RootConstantView>(&ParamView);
1004
- ASSERT_TRUE (RootConstantsView != nullptr );
1005
- EXPECT_THAT_EXPECTED (
1006
- RootConstantsView->read (),
1003
+ ASSERT_THAT_ERROR (
1004
+ ParamView.takeError (),
1007
1005
FailedWithMessage (" Reading structure out of file bounds" ));
1008
1006
}
1009
1007
}
You can’t perform that action at this time.
0 commit comments