Skip to content

Commit dbb4cc6

Browse files
committed
replace insecure use of eval() with proper use of units
1 parent e25cd6c commit dbb4cc6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Mod/Image/ImageTools/_CommandImageScaling.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ def retranslateUi(self, Dialog):
138138
def accept(self):
139139
sel = FreeCADGui.Selection.getSelection()
140140
try:
141-
locale=QtCore.QLocale.system()
142-
d, ok = locale.toFloat(str(eval(self.lineEdit.text())))
141+
try:
142+
q = FreeCAD.Units.parseQuantity(self.lineEdit.text())
143+
d = q.Value
144+
if q.Unit == FreeCAD.Units.Unit(): # plain number
145+
ok = True
146+
elif q.Unit == FreeCAD.Units.Length:
147+
ok = True
148+
except:
149+
ok = False
143150
if not ok:
144151
raise ValueError
145152
s=d/self.distance

0 commit comments

Comments
 (0)