mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-08 11:13:50 +00:00
Fix missing effective accessor alignment validation
Agent-Logs-Url: https://github.com/syoyo/tinygltf/sessions/acb44b6b-9b47-4b84-a4ab-fae35b4b5a71 Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
87b0d175c6
commit
721430aa5f
@@ -250,6 +250,53 @@ TEST_CASE("v3-validate-accessor-invalid-bufferView-index", "[v3][validate][acces
|
||||
tg3_error_stack_free(&errors);
|
||||
}
|
||||
|
||||
TEST_CASE("v3-validate-accessor-misaligned-effective-offset", "[v3][validate][accessor][regression]") {
|
||||
tg3_model model;
|
||||
tg3_error_stack errors;
|
||||
tg3_error_stack_init(&errors);
|
||||
|
||||
const char *json =
|
||||
"{"
|
||||
"\"asset\":{\"version\":\"2.0\"},"
|
||||
"\"buffers\":[{"
|
||||
" \"uri\":\"data:application/octet-stream;base64,AAAAAAAAAAA=\","
|
||||
" \"byteLength\":8"
|
||||
"}],"
|
||||
"\"bufferViews\":[{"
|
||||
" \"buffer\":0,"
|
||||
" \"byteOffset\":2,"
|
||||
" \"byteLength\":4"
|
||||
"}],"
|
||||
"\"accessors\":[{"
|
||||
" \"bufferView\":0,"
|
||||
" \"componentType\":5126,"
|
||||
" \"count\":1,"
|
||||
" \"type\":\"SCALAR\""
|
||||
"}]"
|
||||
"}";
|
||||
parse_json(&model, &errors, json);
|
||||
tg3_error_stack_free(&errors);
|
||||
tg3_error_stack_init(&errors);
|
||||
|
||||
tg3_error_code rc = tg3_validate(&model, &errors);
|
||||
REQUIRE(rc == TG3_ERR_INVALID_ACCESSOR);
|
||||
REQUIRE(tg3_errors_has_error(&errors) == 1);
|
||||
|
||||
bool found = false;
|
||||
for (uint32_t i = 0; i < tg3_errors_count(&errors); i++) {
|
||||
const tg3_error_entry *e = tg3_errors_get(&errors, i);
|
||||
if (e->code == TG3_ERR_INVALID_ACCESSOR &&
|
||||
e->severity == TG3_SEVERITY_ERROR) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
REQUIRE(found);
|
||||
|
||||
tg3_model_free(&model);
|
||||
tg3_error_stack_free(&errors);
|
||||
}
|
||||
|
||||
/* ======================================================================
|
||||
* Tests: mesh validation
|
||||
* ====================================================================== */
|
||||
|
||||
@@ -4695,6 +4695,24 @@ TINYGLTF3_API tg3_error_code tg3_validate(
|
||||
i, (unsigned long long)acc->byte_offset,
|
||||
comp_sz);
|
||||
}
|
||||
/* glTF also requires the effective offset into the
|
||||
* underlying buffer (bufferView.byteOffset +
|
||||
* accessor.byteOffset) to be component-size aligned. */
|
||||
if (((bv->byte_offset + acc->byte_offset) %
|
||||
(uint64_t)comp_sz) != 0) {
|
||||
TG3__VERR(TG3_ERR_INVALID_ACCESSOR, path,
|
||||
"accessor[%u] effective byte offset %llu "
|
||||
"(bufferView[%d].byteOffset %llu + "
|
||||
"accessor.byteOffset %llu) is not aligned "
|
||||
"to componentType size %d",
|
||||
i,
|
||||
(unsigned long long)
|
||||
(bv->byte_offset + acc->byte_offset),
|
||||
acc->buffer_view,
|
||||
(unsigned long long)bv->byte_offset,
|
||||
(unsigned long long)acc->byte_offset,
|
||||
comp_sz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user