Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions devel/215_7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 215_7 Fix array out of bounds issue in graphics mode (#2944)

## How to test
1. Insert a graphics block in Mogan (Insert -> Image -> Draw graphic).
2. Select the ellipse tool in the toolbar and draw an ellipse on the canvas (click twice to set the foci, and a third time to set a point on the boundary).
3. Switch to the selection tool and try to click directly on the ellipse or select it using a rectangular selection (box select).
4. Observe and confirm that the client no longer hangs in an infinite loop or crashes as it did before.

## 2026/03/06 Fix out of bounds caused by `get_control_points`
### What
Fixed a program crash issue when selecting or box-selecting an ellipse.

### Why
In the original `ellipse_rep::get_control_points`, the function informed the caller that it had 3 control points (`np=3`, two foci and one boundary point). However, the `abs` array, which represents the parameter range for each point on the curve, was hardcoded to initialize with only two elements (`array<double> (0.0, 1.0)`). This caused an out-of-bounds access on `abs[2]` during the edge-snapping retrieval or distance calculation in the `curve_box_rep::graphical_select` function (which iterates from 0 to `np` seeking `abs[i]` and `abs[(i+1)%np]`), leading to undefined behavior and infinite loops.

### How
Modified the initialization of `abs` in `ellipse_rep::get_control_points` within `src/Graphics/Types/curve.cpp`. Explicitly expanded the `abs` array to contain 3 elements: `abs << 0.0 << 0.5 << 1.0;`, aligning it with the number of control points returned and preventing out-of-bounds access in exterior loops.
3 changes: 2 additions & 1 deletion src/Graphics/Types/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,8 @@ ellipse_rep::get_control_points (array<double>& abs, array<point>& pts,
// range of parameter values. Since we have a closed curve here, we just need
// to ensure that the starting point has a parameter value of 0 and the ending
// point has a parameter value of 1.
abs = array<double> (0.0, 1.0);
abs= array<double> ();
abs << 0.0 << 0.5 << 1.0;
pts = points;
rcip= cip;
return N (points);
Expand Down