File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ const (
3838 // - Attribute count: 2 bytes
3939 // Total: 50 bytes
4040 triangleSize = (12 * 4 ) + 2
41+
42+ // maxTriangleCount defines the maximum number of triangles allowed in an STL file.
43+ maxTriangleCount = uint64 (math .MaxUint32 )
4144)
4245
4346// bufferWriter encapsulates common buffer writing operations
@@ -140,16 +143,14 @@ func WriteSTLBinary(filename string, triangles []types.Triangle) error {
140143 return err
141144 }
142145
143- triangleCountInt := len (triangles )
144- if triangleCountInt < 0 {
145- return errors .New (errors .ValidationError , "triangle count cannot be negative" , nil )
146- }
147- if triangleCountInt > int (math .MaxUint32 ) {
146+ triangleCount := uint64 (len (triangles ))
147+ if triangleCount > maxTriangleCount {
148148 return errors .New (errors .ValidationError , "triangle count exceeds valid range for STL format" , nil )
149149 }
150150
151- triangleCount := uint32 (triangleCountInt )
152- if err := writeTriangleCount (writer , triangleCount ); err != nil {
151+ // Now safely convert to uint32 since we know it's in range
152+ triangleCountUint32 := uint32 (triangleCount )
153+ if err := writeTriangleCount (writer , triangleCountUint32 ); err != nil {
153154 return err
154155 }
155156
You can’t perform that action at this time.
0 commit comments