mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 18:23:15 +02:00
Add a bit of protection from integer overflows.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/19660
This commit is contained in:
parent
4a64aa9816
commit
31b788c04f
@ -35,6 +35,7 @@
|
|||||||
#include <dialogs/panel_setup_netclasses.h>
|
#include <dialogs/panel_setup_netclasses.h>
|
||||||
#include <tool/tool_manager.h>
|
#include <tool/tool_manager.h>
|
||||||
#include <pcb_painter.h>
|
#include <pcb_painter.h>
|
||||||
|
#include <board_design_settings.h>
|
||||||
#include <string_utils.h>
|
#include <string_utils.h>
|
||||||
#include <view/view.h>
|
#include <view/view.h>
|
||||||
#include <widgets/grid_color_swatch_helpers.h>
|
#include <widgets/grid_color_swatch_helpers.h>
|
||||||
@ -504,16 +505,16 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow()
|
|||||||
|
|
||||||
wxASSERT_MSG( lineIdx >= 0, "Line style name not found." );
|
wxASSERT_MSG( lineIdx >= 0, "Line style name not found." );
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
nc->SetClearance( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE ) );
|
nc->SetClearance( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE ) );
|
||||||
nc->SetTrackWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_TRACKSIZE ) );
|
nc->SetTrackWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_TRACKSIZE ) );
|
||||||
nc->SetViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIASIZE ) );
|
nc->SetViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIASIZE ) );
|
||||||
nc->SetViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIADRILL ) );
|
nc->SetViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_VIADRILL ) );
|
||||||
nc->SetuViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIASIZE ) );
|
nc->SetuViaDiameter( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIASIZE ) );
|
||||||
nc->SetuViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIADRILL ) );
|
nc->SetuViaDrill( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_uVIADRILL ) );
|
||||||
nc->SetDiffPairWidth(
|
nc->SetDiffPairWidth( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
|
||||||
m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_WIDTH ) );
|
nc->SetDiffPairGap( m_netclassGrid->GetOptionalUnitValue( aRow, GRID_DIFF_PAIR_GAP ) );
|
||||||
nc->SetDiffPairGap( m_netclassGrid->GetOptionalUnitValue( aRow,
|
// clang-format on
|
||||||
GRID_DIFF_PAIR_GAP ) );
|
|
||||||
|
|
||||||
if( !nc->IsDefault() )
|
if( !nc->IsDefault() )
|
||||||
{
|
{
|
||||||
@ -590,6 +591,26 @@ bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PANEL_SETUP_NETCLASSES::validateNetclassClearance( int aRow )
|
||||||
|
{
|
||||||
|
// Clip clearance. This is not a nag; we can end up with overflow errors and very poor
|
||||||
|
// performance if the clearance is too large.
|
||||||
|
|
||||||
|
std::optional<int> clearance = m_netclassGrid->GetOptionalUnitValue( aRow, GRID_CLEARANCE );
|
||||||
|
|
||||||
|
if( clearance.has_value() && clearance.value() > MAXIMUM_CLEARANCE )
|
||||||
|
{
|
||||||
|
wxString msg = wxString::Format( _( "Clearance was too large. It has been clipped to %s." ),
|
||||||
|
m_frame->StringFromValue( MAXIMUM_CLEARANCE, true ) );
|
||||||
|
PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_CLEARANCE );
|
||||||
|
m_netclassGrid->SetUnitValue( aRow, GRID_CLEARANCE, MAXIMUM_CLEARANCE );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging( wxGridEvent& event )
|
void PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging( wxGridEvent& event )
|
||||||
{
|
{
|
||||||
if( event.GetCol() == GRID_NAME )
|
if( event.GetCol() == GRID_NAME )
|
||||||
@ -615,6 +636,10 @@ void PANEL_SETUP_NETCLASSES::OnNetclassGridCellChanging( wxGridEvent& event )
|
|||||||
event.Veto();
|
event.Veto();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( event.GetCol() == GRID_CLEARANCE )
|
||||||
|
{
|
||||||
|
validateNetclassClearance( event.GetRow() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -901,8 +926,6 @@ bool PANEL_SETUP_NETCLASSES::Validate()
|
|||||||
if( !m_netclassGrid->CommitPendingChanges() || !m_assignmentGrid->CommitPendingChanges() )
|
if( !m_netclassGrid->CommitPendingChanges() || !m_assignmentGrid->CommitPendingChanges() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxString msg;
|
|
||||||
|
|
||||||
// Test net class parameters.
|
// Test net class parameters.
|
||||||
for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
|
for( int row = 0; row < m_netclassGrid->GetNumberRows(); row++ )
|
||||||
{
|
{
|
||||||
@ -912,6 +935,9 @@ bool PANEL_SETUP_NETCLASSES::Validate()
|
|||||||
|
|
||||||
if( !validateNetclassName( row, netclassName, false ) )
|
if( !validateNetclassName( row, netclassName, false ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if( !validateNetclassClearance( row ) )
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -101,6 +101,8 @@
|
|||||||
#define MINIMUM_ERROR_SIZE_MM 0.001 // For arc approximation
|
#define MINIMUM_ERROR_SIZE_MM 0.001 // For arc approximation
|
||||||
#define MAXIMUM_ERROR_SIZE_MM 0.1 // For arc approximation
|
#define MAXIMUM_ERROR_SIZE_MM 0.1 // For arc approximation
|
||||||
|
|
||||||
|
#define MAXIMUM_CLEARANCE pcbIUScale.mmToIU( 500 ) // to prevent int-overflows
|
||||||
|
|
||||||
// Min/max values used in dialogs to validate settings
|
// Min/max values used in dialogs to validate settings
|
||||||
#define MINIMUM_LINE_WIDTH_MM 0.005 // minimal line width entered in a dialog
|
#define MINIMUM_LINE_WIDTH_MM 0.005 // minimal line width entered in a dialog
|
||||||
#define MAXIMUM_LINE_WIDTH_MM 100.0 // max line width entered in a dialog
|
#define MAXIMUM_LINE_WIDTH_MM 100.0 // max line width entered in a dialog
|
||||||
|
@ -65,6 +65,7 @@ private:
|
|||||||
void onUnitsChanged( wxCommandEvent& aEvent );
|
void onUnitsChanged( wxCommandEvent& aEvent );
|
||||||
|
|
||||||
bool validateNetclassName( int aRow, const wxString& aName, bool focusFirst = true );
|
bool validateNetclassName( int aRow, const wxString& aName, bool focusFirst = true );
|
||||||
|
bool validateNetclassClearance( int aRow );
|
||||||
|
|
||||||
void rebuildNetclassDropdowns();
|
void rebuildNetclassDropdowns();
|
||||||
|
|
||||||
|
@ -1311,7 +1311,8 @@ int BOARD_DESIGN_SETTINGS::GetBiggestClearanceValue() const
|
|||||||
biggest = std::max( biggest, constraint.Value().Min() );
|
biggest = std::max( biggest, constraint.Value().Min() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return biggest;
|
// Clip to avoid integer overflows in subsequent calculations
|
||||||
|
return std::min( biggest, MAXIMUM_CLEARANCE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -746,6 +746,24 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRules( DRC_CONSTRAINT_T aConstraintType, const BO
|
|||||||
if( c->constraint.m_Value.HasMax() )
|
if( c->constraint.m_Value.HasMax() )
|
||||||
constraint .m_Value.SetMax( c->constraint.m_Value.Max() );
|
constraint .m_Value.SetMax( c->constraint.m_Value.Max() );
|
||||||
|
|
||||||
|
switch( c->constraint.m_Type )
|
||||||
|
{
|
||||||
|
case CLEARANCE_CONSTRAINT:
|
||||||
|
case COURTYARD_CLEARANCE_CONSTRAINT:
|
||||||
|
case SILK_CLEARANCE_CONSTRAINT:
|
||||||
|
case HOLE_CLEARANCE_CONSTRAINT:
|
||||||
|
case EDGE_CLEARANCE_CONSTRAINT:
|
||||||
|
case PHYSICAL_CLEARANCE_CONSTRAINT:
|
||||||
|
case PHYSICAL_HOLE_CLEARANCE_CONSTRAINT:
|
||||||
|
if( constraint.m_Value.Min() > MAXIMUM_CLEARANCE )
|
||||||
|
constraint.m_Value.SetMin( MAXIMUM_CLEARANCE );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// While the expectation would be to OR the disallow flags, we've already
|
// While the expectation would be to OR the disallow flags, we've already
|
||||||
// masked them down to aItem's type -- so we're really only looking for a
|
// masked them down to aItem's type -- so we're really only looking for a
|
||||||
// boolean here.
|
// boolean here.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user