1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +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,41 +6287,58 @@ 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++)
{
Handle(StepRepr_RepresentationItem) anItem = aReprItems->Value(anIndex);
if (anItem.IsNull())
continue;
if (anItem->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) for (Standard_Integer anIndex = aReprItems->Lower(); anIndex <= aReprItems->Upper(); anIndex++)
{
Handle(StepRepr_RepresentationItem) anItem = aReprItems->Value(anIndex);
if (anItem.IsNull())
continue;
if (anItem->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem)))
{
Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem =
Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(anItem);
Handle(TCollection_HAsciiString) aDescription = aDescrItem->Description();
if (!aDescription.IsNull())
{ {
Handle(StepRepr_DescriptiveRepresentationItem) aDescrItem = theAttr->SetString(aPropName, aDescription->ToCString());
Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(anItem);
Handle(TCollection_HAsciiString) aDescription = aDescrItem->Description();
theAttr->SetString(thePropDef->Name()->ToCString(), 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)::DownCast(anItem);
if (aMeasureItem->Measure().IsNull()
|| aMeasureItem->Measure()->ValueComponentMember().IsNull())
{ {
Handle(StepRepr_MeasureRepresentationItem) aMeasureItem = continue;
Handle(StepRepr_MeasureRepresentationItem)::DownCast(anItem); }
Standard_Real aValue = aMeasureItem->Measure()->ValueComponent();
TCollection_AsciiString aValType = Standard_Real aValue = aMeasureItem->Measure()->ValueComponent();
aMeasureItem->Measure()->ValueComponentMember()->Name(); TCollection_AsciiString aValType = aMeasureItem->Measure()->ValueComponentMember()->Name();
StepBasic_Unit anUnit = aMeasureItem->Measure()->UnitComponent(); StepBasic_Unit anUnit = aMeasureItem->Measure()->UnitComponent();
if (!anUnit.IsNull())
if (!anUnit.IsNull())
{
if (anUnit.Type() == STANDARD_TYPE(StepBasic_DerivedUnit))
{ {
Standard_Real aParam = 1.; Handle(StepBasic_DerivedUnit) aDUnit = anUnit.DerivedUnit();
if (anUnit.Type() == STANDARD_TYPE(StepBasic_DerivedUnit)) if (!aDUnit.IsNull())
{ {
Handle(StepBasic_DerivedUnit) aDUnit = anUnit.DerivedUnit(); 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);
Standard_Real anExp = aDUElem->Exponent(); if (aDUElem.IsNull())
Handle(StepBasic_NamedUnit) aNUnit = aDUElem->Unit(); continue;
Standard_Real anExp = aDUElem->Exponent();
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,71 +6379,84 @@ Standard_Boolean STEPCAFControl_Reader::fillAttributes(
} }
aValue = aValue * aParam; aValue = aValue * aParam;
} }
else }
else
{
Handle(StepBasic_NamedUnit) aNUnit = anUnit.NamedUnit();
if (!aNUnit.IsNull())
{ {
Handle(StepBasic_NamedUnit) aNUnit = anUnit.NamedUnit(); Standard_Real aParam = 1.;
if (!aNUnit.IsNull()) if (aNUnit->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit)))
{ {
if (aNUnit->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndMassUnit))) Standard_Real aFact = 1.;
if (GetMassConversionFactor(aNUnit, aFact))
{ {
Standard_Real aFact = 1.; aValue *= aFact;
if (GetMassConversionFactor(aNUnit, aFact))
{
aValue *= aFact;
}
} }
else }
{ else
STEPConstruct_UnitContext anUnitCtx; {
anUnitCtx.ComputeFactors(aNUnit, theLocalFactors); STEPConstruct_UnitContext anUnitCtx;
if (anUnitCtx.AreaDone()) anUnitCtx.ComputeFactors(aNUnit, theLocalFactors);
aParam = anUnitCtx.AreaFactor(); if (anUnitCtx.AreaDone())
if (anUnitCtx.VolumeDone()) aParam = anUnitCtx.AreaFactor();
aParam = anUnitCtx.VolumeFactor(); if (anUnitCtx.VolumeDone())
if (anUnitCtx.LengthDone()) aParam = anUnitCtx.VolumeFactor();
aParam = anUnitCtx.LengthFactor(); if (anUnitCtx.LengthDone())
aParam = anUnitCtx.LengthFactor();
aValue *= aParam; aValue *= aParam;
}
} }
} }
} }
theAttr->SetReal(thePropDef->Name()->ToCString(), aValue);
} }
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_ValueRepresentationItem))) theAttr->SetReal(aPropName, aValue);
continue;
}
if (anItem->IsKind(STANDARD_TYPE(StepRepr_ValueRepresentationItem)))
{
Handle(StepRepr_ValueRepresentationItem) aValueItem =
Handle(StepRepr_ValueRepresentationItem)::DownCast(anItem);
Handle(StepBasic_MeasureValueMember) aMeasureValueMem = aValueItem->ValueComponentMember();
if (!aMeasureValueMem.IsNull())
{ {
Handle(StepRepr_ValueRepresentationItem) aValueItem =
Handle(StepRepr_ValueRepresentationItem)::DownCast(anItem);
Handle(StepBasic_MeasureValueMember) aMeasureValueMem =
aValueItem->ValueComponentMember();
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;
{ }
Handle(StepRepr_IntegerRepresentationItem) anIntegerItem =
Handle(StepRepr_IntegerRepresentationItem)::DownCast(anItem); if (anItem->IsKind(STANDARD_TYPE(StepRepr_IntegerRepresentationItem)))
theAttr->SetInteger(thePropDef->Name()->ToCString(), anIntegerItem->Value()); {
} Handle(StepRepr_IntegerRepresentationItem) anIntegerItem =
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_RealRepresentationItem))) Handle(StepRepr_IntegerRepresentationItem)::DownCast(anItem);
{ theAttr->SetInteger(aPropName, anIntegerItem->Value());
Handle(StepRepr_RealRepresentationItem) aRealItem = continue;
Handle(StepRepr_RealRepresentationItem)::DownCast(anItem); }
theAttr->SetReal(thePropDef->Name()->ToCString(), aRealItem->Value());
} if (anItem->IsKind(STANDARD_TYPE(StepRepr_RealRepresentationItem)))
else if (anItem->IsKind(STANDARD_TYPE(StepRepr_BooleanRepresentationItem))) {
{ Handle(StepRepr_RealRepresentationItem) aRealItem =
Handle(StepRepr_BooleanRepresentationItem) aBoolItem = Handle(StepRepr_RealRepresentationItem)::DownCast(anItem);
Handle(StepRepr_BooleanRepresentationItem)::DownCast(anItem); theAttr->SetReal(aPropName, aRealItem->Value());
theAttr->SetInteger(thePropDef->Name()->ToCString(), aBoolItem->Value()); continue;
} }
if (anItem->IsKind(STANDARD_TYPE(StepRepr_BooleanRepresentationItem)))
{
Handle(StepRepr_BooleanRepresentationItem) aBoolItem =
Handle(StepRepr_BooleanRepresentationItem)::DownCast(anItem);
theAttr->SetInteger(aPropName, aBoolItem->Value());
continue;
} }
} }
} }