commit c9de363126bb34112b76f85268ba1c7d9593135c
parent 0f251e10c9291d52793f8eb16c7b4d1bb95b601d
Author: Louis Burda <quent.burda@gmail.com>
Date: Thu, 8 Jul 2021 10:13:40 +0200
made stl parsing more robus by checking parent for each layer, added installation of normal checker requirements for linting check
Diffstat:
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/enochecker_test.yml b/.github/workflows/enochecker_test.yml
@@ -31,6 +31,7 @@ jobs:
- name: Test checker style
run: |
cd checker
+ pip install -r src/requirements.txt
pip install -r dev-requirements.txt
make lint
- name: Start service
diff --git a/src/stlfile.c b/src/stlfile.c
@@ -62,6 +62,13 @@ stack_ind(struct stack *stack, int search)
}
int
+stack_top_eq(struct stack *stack, int cmp)
+{
+ if (!stack->count) return 0;
+ return stack->data[stack->count-1] == cmp;
+}
+
+int
isws(char c)
{
return c && strchr(wsset, c);
@@ -131,11 +138,11 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
while ((kw = consume_keyword(&bp))) {
switch (kw) {
case KW_SOLID_BEGIN:
- stack_push(&states, STATE_SOLID);
- if (stack_ind(&states, KW_SOLID_BEGIN) != -1) {
- FMT_ERR("Multiple nested solids!\n");
+ if (states.count) {
+ FMT_ERR("Improper nesting, solid not top-level in STL\n");
goto fail;
}
+ stack_push(&states, STATE_SOLID);
tmp = bp;
if (!consume_keyword(&bp)
&& (arg = consume_arg(&bp, &end))) {
@@ -162,11 +169,11 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
}
break;
case KW_LOOP_BEGIN:
- stack_push(&states, STATE_LOOP);
- if (stack_ind(&states, KW_LOOP_BEGIN) != -1) {
- FMT_ERR("Multiple nested loops!\n");
+ if (!stack_top_eq(&states, STATE_FACET)) {
+ FMT_ERR("Loop parent is not a facet!\n");
goto fail;
}
+ stack_push(&states, STATE_LOOP);
break;
case KW_LOOP_END:
if ((kw = stack_pop(&states)) != STATE_LOOP) {
@@ -177,11 +184,11 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
info->loopcount++;
break;
case KW_FACET_BEGIN:
- stack_push(&states, STATE_FACET);
- if (stack_ind(&states, KW_LOOP_BEGIN) != -1) {
- FMT_ERR("Multiple nested facets!\n");
+ if (!stack_top_eq(&states, STATE_SOLID)) {
+ FMT_ERR("Facet parent is not a solid!\n");
goto fail;
}
+ stack_push(&states, STATE_FACET);
for (i = 0; i < 3; i++) {
if (!(arg = consume_arg(&bp, &end))) {
FMT_ERR("Facet with < 3 args!\n");
@@ -202,6 +209,10 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
}
break;
case KW_VERTEX:
+ if (!stack_top_eq(&states, STATE_LOOP)) {
+ FMT_ERR("Vertex parent is not a loop!\n");
+ goto fail;
+ }
for (i = 0; i < 3; i++) {
if (!(arg = consume_arg(&bp, &end))) {
FMT_ERR("Vertex with < 3 args\n");