diff --git a/src/BRepFill/BRepFill_Sweep.cxx b/src/BRepFill/BRepFill_Sweep.cxx
index 578ad6cfe7..d5e9439330 100644
--- a/src/BRepFill/BRepFill_Sweep.cxx
+++ b/src/BRepFill/BRepFill_Sweep.cxx
@@ -3052,10 +3052,19 @@ void BRepFill_Sweep::Build(TopTools_MapOfShape& ReversedEdges,
         if (i2 > myFaces->UpperRow())
           i2 = 0;
         if (i1 != 0)
-          Face1 = TopoDS::Face(myFaces->Value(i1, jj));
+        {
+          const TopoDS_Shape& aShape1 = myFaces->Value(i1, jj);
+          if (aShape1.ShapeType() == TopAbs_FACE)
+            Face1 = TopoDS::Face(aShape1);
+        }
         if (i2 != 0)
-          Face2 = TopoDS::Face(myFaces->Value(i2, jj));
-        CorrectSameParameter(anEdge, Face1, Face2);
+        {
+          const TopoDS_Shape& aShape2 = myFaces->Value(i2, jj);
+          if (aShape2.ShapeType() == TopAbs_FACE)
+            Face2 = TopoDS::Face(aShape2);
+        }
+        if (!Face1.IsNull() && !Face2.IsNull())
+          CorrectSameParameter(anEdge, Face1, Face2);
       }
     }
 
diff --git a/tests/bugs/modalg_7/bug30204_1 b/tests/bugs/modalg_7/bug30204_1
new file mode 100644
index 0000000000..e4da5dc033
--- /dev/null
+++ b/tests/bugs/modalg_7/bug30204_1
@@ -0,0 +1,17 @@
+puts "============"
+puts "OCC30204"
+puts "============"
+puts ""
+###################################
+# BRepOffsetAPI_MakePipeShell crash
+###################################
+
+#test only for no crash
+
+restore [locate_data_file bug30204_path.brep] path
+restore [locate_data_file bug30204_base.brep] base
+
+mksweep path
+setsweep -CN 0 1 0
+addsweep base
+buildsweep result
diff --git a/tests/bugs/modalg_7/bug30204_2 b/tests/bugs/modalg_7/bug30204_2
new file mode 100644
index 0000000000..767593caab
--- /dev/null
+++ b/tests/bugs/modalg_7/bug30204_2
@@ -0,0 +1,26 @@
+puts "============"
+puts "OCC30204"
+puts "============"
+puts ""
+###################################
+# BRepOffsetAPI_MakePipeShell crash
+###################################
+
+restore [locate_data_file bug30204_path.brep] path
+restore [locate_data_file bug30204_base.brep] base
+
+mksweep path
+addsweep base
+buildsweep result
+
+checkshape result
+
+checknbshapes result -shell 1 -face 20 -wire 20 -edge 44 -vertex 24
+
+set tolres [checkmaxtol result]
+
+if { ${tolres} > 2.e-7} {
+   puts "Error: bad tolerance of result"
+}
+
+checkprops result -s 6851.98