CVE-2022-0496 (published 2022-08-29T15:15Z)

A vulnerbiility was found in Openscad, where a DXF-format drawing with particular (not necessarily malformed!) properties may cause an out-of-bounds memory access when imported using import().

CVSS v3 base score: 5.5, MEDIUM (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-125
cwe_name: Out-of-bounds Read
description: The product reads data past the end, or before the beginning, of the intended buffer.
extended_description: 
            
            
             
			 
         
         

Fix information:
repo_url: https://github.com/openscad/openscad
commit_details: repo_url: https://github.com/openscad/openscad
author: ChrisCoxArt
author_date: 2022-01-15 19:40:09-08:00
msg: add safety to line lookups in DXF import, fixes #4037

Add safety (test for, and continue past, bad indices).
Report warnings about bad indices
Add variables just to make the array indices easier to read and debug.
repository: repo_url: https://github.com/openscad/openscad
repo_name: openscad/openscad
description: OpenSCAD - The Programmers Solid 3D CAD Modeller  
repo_language: C++
owner: openscad
file_changes: filename: dxfdata.cc
change_type: ModificationType.MODIFY
diff: @@ -441,6 +441,11 @@ DxfData::DxfData(double fn, double fs, double fa,
 				auto lv = grid.data(this->points[lines[idx].idx[j]][0], this->points[lines[idx].idx[j]][1]);
 				for (size_t ki = 0; ki < lv.size(); ++ki) {
 					int k = lv.at(ki);
+                    if (k < 0 || k >= lines.size()) {
+                        LOG(message_group::Warning,Location::NONE,"",
+                            "Bad DXF line index in %1$s.",QuotedString(boostfs_uncomplete(filename, fs::current_path()).generic_string()));
+                        continue;
+                    }
 					if (k == idx || lines[k].disabled) continue;
 					goto next_open_path_j;
 				}
@@ -466,13 +471,20 @@ DxfData::DxfData(double fn, double fs, double fa,
 			auto lv = grid.data(ref_point[0], ref_point[1]);
 			for (size_t ki = 0; ki < lv.size(); ++ki) {
 				int k = lv.at(ki);
+                if (k < 0 || k >= lines.size()) {
+                    LOG(message_group::Warning,Location::NONE,"",
+                        "Bad DXF line index in %1$s.",QuotedString(boostfs_uncomplete(filename, fs::current_path()).generic_string()));
+                    continue;
+                }
 				if (lines[k].disabled) continue;
-				if (grid.eq(ref_point[0], ref_point[1], this->points[lines[k].idx[0]][0], this->points[lines[k].idx[0]][1])) {
+                auto idk0 = lines[k].idx[0];    // make it easier to read and debug
+                auto idk1 = lines[k].idx[1];
+				if (grid.eq(ref_point[0], ref_point[1], this->points[idk0][0], this->points[idk0][1])) {
 					current_line = k;
 					current_point = 0;
 					goto found_next_line_in_open_path;
 				}
-				if (grid.eq(ref_point[0], ref_point[1], this->points[lines[k].idx[1]][0], this->points[lines[k].idx[1]][1])) {
+				if (grid.eq(ref_point[0], ref_point[1], this->points[idk1][0], this->points[idk1][1])) {
 					current_line = k;
 					current_point = 1;
 					goto found_next_line_in_open_path;
@@ -501,13 +513,20 @@ DxfData::DxfData(double fn, double fs, double fa,
 			auto lv = grid.data(ref_point[0], ref_point[1]);
 			for (size_t ki = 0; ki < lv.size(); ++ki) {
 				int k = lv.at(ki);
+                if (k < 0 || k >= lines.size()) {
+                    LOG(message_group::Warning,Location::NONE,"",
+                        "Bad DXF line index in %1$s.",QuotedString(boostfs_uncomplete(filename, fs::current_path()).generic_string()));
+                    continue;
+                }
 				if (lines[k].disabled) continue;
-				if (grid.eq(ref_point[0], ref_point[1], this->points[lines[k].idx[0]][0], this->points[lines[k].idx[0]][1])) {
+                auto idk0 = lines[k].idx[0];    // make it easier to read and debug
+                auto idk1 = lines[k].idx[1];
+				if (grid.eq(ref_point[0], ref_point[1], this->points[idk0][0], this->points[idk0][1])) {
 					current_line = k;
 					current_point = 0;
 					goto found_next_line_in_closed_path;
 				}
-					if (grid.eq(ref_point[0], ref_point[1], this->points[lines[k].idx[1]][0], this->points[lines[k].idx[1]][1])) {
+                if (grid.eq(ref_point[0], ref_point[1], this->points[idk1][0], this->points[idk1][1])) {
 					current_line = k;
 					current_point = 1;
 					goto found_next_line_in_closed_path;

programming_language: C++