From 66df176447d36c546b3436f8d708048ac0e36575 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 26 Mar 2017 15:20:24 -0500 Subject: [PATCH] Abort loading if the file size is larger than the reported # of facets in the file header. --- xs/src/admesh/stlinit.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xs/src/admesh/stlinit.c b/xs/src/admesh/stlinit.c index a191e3d764..f830566216 100644 --- a/xs/src/admesh/stlinit.c +++ b/xs/src/admesh/stlinit.c @@ -131,6 +131,12 @@ stl_count_facets(stl_file *stl, const char *file) { if((!fread(&header_num_facets, sizeof(int), 1, stl->fp)) || (num_facets != header_num_facets)) { fprintf(stderr, "Warning: File size doesn't match number of facets in the header\n"); + + if(num_facets > header_num_facets) { + // this file is garbage. + stl->error = 1; + return; + } } } /* Otherwise, if the .STL file is ASCII, then do the following */