Repository navigation
Reject bad numbers before any edit, with GIMP's own ranges (#152, #160) - #190
Conversation
A PDB config given a number outside its argument's range, NaN included, keeps the argument's default (for hue-offset, -180) and the procedure returns SUCCESS. NaN and inf also got past several tools' checks, and the GEGL filter tools checked their values only inside the undo group. _number() checks a tool parameter: a finite number within [lo, hi], with an error naming the parameter. _pdb_number() and _gegl_number() read the bounds from the PDB argument or GEGL property the value is sent as. All 16 affected tools check before the undo group opens.
|
No actionable comments were generated in the recent review. WalkthroughThe plugin now validates numeric inputs for image tools against finite-value, integer, and GIMP or GEGL parameter bounds before image changes. Offline and live regression tests cover invalid inputs and selected valid boundary values. ChangesNumeric Parameter Validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Possibly related PRs
Suggested labels: Suggested reviewers: Merge Risk:
|
* Document the number ranges the tools check since #190 sharpen's amount said 0-500 and apply_emboss's elevation 0-90, while the tools accept GIMP's ranges, 0-30000 and 0-180. The blur radii, block_size, feather and the text sizes had no range in their description. * apply_pixelate: give block_size's upper bound too
Fixes #152. Fixes #160.
Problem
NaNincluded, keeps the argument's default and the procedure returns SUCCESS. Forgimp-drawable-hue-saturationthat default is the minimum, soadjust_hue_saturation(hue=500)rotated the hue by -180 and reported success.NaNand infinity got past several tools' own checks, and the GEGL filter tools checked their values only inside their undo group. The call failed, but the image was left marked as changed, and the error named GEGL's property on its own scale (gegl:unsharp-mask scale=300.01 is outside [0.0, 300.0]forsharpen(amount=30001)).Change
One check, with ranges read from GIMP:
_number(value, name, lo, hi, scale): a finite number within[lo, hi], or aValueErrornaming the tool's parameter, e.g.hue must be between -180 and 180, got 500.scalecovers tools that convert the value (sharpen'samount/ 100), so the message uses the tool's scale. Ends GIMP marks as unbounded (G_MAXDOUBLE / G_MAXINT) are left out of the message unless the value is past them._pdb_number(proc, arg, ...)reads the bounds from the PDB argument (proc.find_argument)._gegl_number(op, key, ...)reads them from the GEGL property (Gimp.DrawableFilter.operation_get_pspecs), without creating a filter.All 16 affected tools now check before the undo group opens, or before any other change:
adjust_hue_saturationadjust_color_balancesharpen,blur,apply_gaussian_blur,apply_pixelate,apply_emboss,apply_vignette,apply_noisedenoisecannot convert float NaN to integerselect_rectangle,select_ellipsedraw_linegradient_fillcreate_layerconstructor returned NULLadd_textedit_text)_apply_gegl_filter's own check is kept as a backstop.edit_textkeeps the 8192 limit from #150.warp_region, listed in #152, already checks its values since the #63 port.Tests
tests/test_number_ranges.py(offline): 41 bad values across the 16 tools each return an error naming the parameter, with no undo group, selection, paint or filter call; values at the ends of each range pass; unit tests for the helper. All 41 fail onmain. The gi stub intest_pdb_status.pygainsGimp.DrawableFilter.operation_get_pspecsandFakeProc.find_argument, with GIMP 3.2.8's ranges.tests/test_number_ranges_live.py: the same 41 bad values on GIMP 3.2.8 leave the image clean (dirty flag, layers, selection, pixels), and values at the ends of the ranges work. Onmain's plugin, 34 of them changed the image (40 probed;block_size=2**31was added later, after CodeRabbit's CLI review).Summary by CodeRabbit
NaN, infinity, fractional values where integers are required, and out-of-range values—return an error identifying the affected parameter.