1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

Data Exchange - Step Import metadata crash protecting #357

Fix null checks and improve attribute handling in STEPCAFControl_Reader
This commit is contained in:
Pasukhin Dmitry 2025-02-12 15:25:19 +01:00 committed by GitHub
parent f423143109
commit a8950426b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6266,17 +6266,18 @@ Standard_Boolean STEPCAFControl_Reader::fillAttributes(
const StepData_Factors& theLocalFactors, const StepData_Factors& theLocalFactors,
Handle(TDataStd_NamedData)& theAttr) const Handle(TDataStd_NamedData)& theAttr) const
{ {
// skip if key is null // Skip if property definition or name is null
if (thePropDef->Name().IsNull()) if (thePropDef.IsNull() || thePropDef->Name().IsNull())
{ {
return Standard_False; return Standard_False;
} }
Handle(StepRepr_PropertyDefinitionRepresentation) aPropDefRepr; const TCollection_AsciiString& aPropName = thePropDef->Name()->String();
Interface_EntityIterator aSharingListOfPD = theWS->Graph().Sharings(thePropDef); Interface_EntityIterator aSharingListOfPD = theWS->Graph().Sharings(thePropDef);
for (aSharingListOfPD.Start(); aSharingListOfPD.More(); aSharingListOfPD.Next()) for (aSharingListOfPD.Start(); aSharingListOfPD.More(); aSharingListOfPD.Next())
{ {
aPropDefRepr = Handle(StepRepr_PropertyDefinitionRepresentation) aPropDefRepr =
Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(aSharingListOfPD.Value()); Handle(StepRepr_PropertyDefinitionRepresentation)::DownCast(aSharingListOfPD.Value());
if (aPropDefRepr.IsNull()) if (aPropDefRepr.IsNull())
continue; continue;
@ -6286,10 +6287,10 @@ Standard_Boolean STEPCAFControl_Reader::fillAttributes(
continue; continue;
Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = aUsedRepr->Items(); Handle(StepRepr_HArray1OfRepresentationItem) aReprItems = aUsedRepr->Items();
if (!aReprItems.IsNull()) if (aReprItems.IsNull())
{ continue;
for (Standard_Integer anIndex = aReprItems->Lower(); anIndex <= aReprItems->Upper();
anIndex++) for (Standard_Integer anIndex = aReprItems->Lower(); anIndex <= aReprItems->Upper(); anIndex++)
{ {
Handle(StepRepr_RepresentationItem) anItem = aReprItems->Value(anIndex); Handle(StepRepr_RepresentationItem) anItem = aReprItems->Value(anIndex);
if (anItem.IsNull()) if (anItem.IsNull())
@ -6300,27 +6301,44 @@ Standard_Boolean STEPCAFControl_Reader::fillAttributes(
Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem = Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem =
Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(anItem); Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(anItem);
Handle(TCollection_HAsciiString) aDescription = aDescrItem->Description(); Handle(TCollection_HAsciiString) aDescription = aDescrItem->Description();
theAttr->SetString(thePropDef->Name()->ToCString(), aDescription->ToCString()); if (!aDescription.IsNull())
{
theAttr->SetString(aPropName, aDescription->ToCString());
} }
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem))) continue;
}
if (anItem->IsKind(STANDARD_TYPE(StepRepr_MeasureRepresentationItem)))
{ {
Handle(StepRepr_MeasureRepresentationItem) aMeasureItem = Handle(StepRepr_MeasureRepresentationItem) aMeasureItem =
Handle(StepRepr_MeasureRepresentationItem)::DownCast(anItem); Handle(StepRepr_MeasureRepresentationItem)::DownCast(anItem);
if (aMeasureItem->Measure().IsNull()
|| aMeasureItem->Measure()->ValueComponentMember().IsNull())
{
continue;
}
Standard_Real aValue = aMeasureItem->Measure()->ValueComponent(); Standard_Real aValue = aMeasureItem->Measure()->ValueComponent();
TCollection_AsciiString aValType = TCollection_AsciiString aValType = aMeasureItem->Measure()->ValueComponentMember()->Name();
aMeasureItem->Measure()->ValueComponentMember()->Name();
StepBasic_Unit anUnit = aMeasureItem->Measure()->UnitComponent(); StepBasic_Unit anUnit = aMeasureItem->Measure()->UnitComponent();
if (!anUnit.IsNull()) if (!anUnit.IsNull())
{ {
Standard_Real aParam = 1.;
if (anUnit.Type() == STANDARD_TYPE(StepBasic_DerivedUnit)) if (anUnit.Type() == STANDARD_TYPE(StepBasic_DerivedUnit))
{ {
Handle(StepBasic_DerivedUnit) aDUnit = anUnit.DerivedUnit(); Handle(StepBasic_DerivedUnit) aDUnit = anUnit.DerivedUnit();
if (!aDUnit.IsNull())
{
Standard_Real aParam = 1.;
for (Standard_Integer anInd = 1; anInd <= aDUnit->NbElements(); ++anInd) for (Standard_Integer anInd = 1; anInd <= aDUnit->NbElements(); ++anInd)
{ {
Handle(StepBasic_DerivedUnitElement) aDUElem = aDUnit->ElementsValue(anInd); Handle(StepBasic_DerivedUnitElement) aDUElem = aDUnit->ElementsValue(anInd);
if (aDUElem.IsNull())
continue;
Standard_Real anExp = aDUElem->Exponent(); Standard_Real anExp = aDUElem->Exponent();
Handle(StepBasic_NamedUnit) aNUnit = aDUElem->Unit(); Handle(StepBasic_NamedUnit) aNUnit = aDUElem->Unit();
if (!aNUnit.IsNull()) if (!aNUnit.IsNull())
{ {
if (aNUnit->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) if (aNUnit->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit))
@ -6361,11 +6379,13 @@ Standard_Boolean STEPCAFControl_Reader::fillAttributes(
} }
aValue = aValue * aParam; aValue = aValue * aParam;
} }
}
else else
{ {
Handle(StepBasic_NamedUnit) aNUnit = anUnit.NamedUnit(); Handle(StepBasic_NamedUnit) aNUnit = anUnit.NamedUnit();
if (!aNUnit.IsNull()) if (!aNUnit.IsNull())
{ {
Standard_Real aParam = 1.;
if (aNUnit->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) if (aNUnit->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)))
{ {
Standard_Real aFact = 1.; Standard_Real aFact = 1.;
@ -6390,42 +6410,53 @@ Standard_Boolean STEPCAFControl_Reader::fillAttributes(
} }
} }
} }
theAttr->SetReal(thePropDef->Name()->ToCString(), aValue); theAttr->SetReal(aPropName, aValue);
continue;
} }
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_ValueRepresentationItem)))
if (anItem->IsKind(STANDARD_TYPE(StepRepr_ValueRepresentationItem)))
{ {
Handle(StepRepr_ValueRepresentationItem) aValueItem = Handle(StepRepr_ValueRepresentationItem) aValueItem =
Handle(StepRepr_ValueRepresentationItem)::DownCast(anItem); Handle(StepRepr_ValueRepresentationItem)::DownCast(anItem);
Handle(StepBasic_MeasureValueMember) aMeasureValueMem = Handle(StepBasic_MeasureValueMember) aMeasureValueMem = aValueItem->ValueComponentMember();
aValueItem->ValueComponentMember();
if (!aMeasureValueMem.IsNull())
{
Interface_ParamType aParamType = aMeasureValueMem->ParamType(); Interface_ParamType aParamType = aMeasureValueMem->ParamType();
if (aParamType == Interface_ParamInteger) if (aParamType == Interface_ParamInteger)
{ {
theAttr->SetInteger(thePropDef->Name()->ToCString(), aMeasureValueMem->Integer()); theAttr->SetInteger(aPropName, aMeasureValueMem->Integer());
} }
else if (aParamType == Interface_ParamReal) else if (aParamType == Interface_ParamReal)
{ {
theAttr->SetReal(thePropDef->Name()->ToCString(), aMeasureValueMem->Real()); theAttr->SetReal(aPropName, aMeasureValueMem->Real());
} }
} }
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_IntegerRepresentationItem))) continue;
}
if (anItem->IsKind(STANDARD_TYPE(StepRepr_IntegerRepresentationItem)))
{ {
Handle(StepRepr_IntegerRepresentationItem) anIntegerItem = Handle(StepRepr_IntegerRepresentationItem) anIntegerItem =
Handle(StepRepr_IntegerRepresentationItem)::DownCast(anItem); Handle(StepRepr_IntegerRepresentationItem)::DownCast(anItem);
theAttr->SetInteger(thePropDef->Name()->ToCString(), anIntegerItem->Value()); theAttr->SetInteger(aPropName, anIntegerItem->Value());
continue;
} }
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_RealRepresentationItem)))
if (anItem->IsKind(STANDARD_TYPE(StepRepr_RealRepresentationItem)))
{ {
Handle(StepRepr_RealRepresentationItem) aRealItem = Handle(StepRepr_RealRepresentationItem) aRealItem =
Handle(StepRepr_RealRepresentationItem)::DownCast(anItem); Handle(StepRepr_RealRepresentationItem)::DownCast(anItem);
theAttr->SetReal(thePropDef->Name()->ToCString(), aRealItem->Value()); theAttr->SetReal(aPropName, aRealItem->Value());
continue;
} }
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_BooleanRepresentationItem)))
if (anItem->IsKind(STANDARD_TYPE(StepRepr_BooleanRepresentationItem)))
{ {
Handle(StepRepr_BooleanRepresentationItem) aBoolItem = Handle(StepRepr_BooleanRepresentationItem) aBoolItem =
Handle(StepRepr_BooleanRepresentationItem)::DownCast(anItem); Handle(StepRepr_BooleanRepresentationItem)::DownCast(anItem);
theAttr->SetInteger(thePropDef->Name()->ToCString(), aBoolItem->Value()); theAttr->SetInteger(aPropName, aBoolItem->Value());
} continue;
} }
} }
} }