Skip to content

Commit

Permalink
Fixed a crash when loading some IQM models with null blend weights.
Browse files Browse the repository at this point in the history
The crash was caused by adding a nonzero offset to a null pointer, thereby making the pointer non-null but invalid.
  • Loading branch information
apanteleev committed Aug 23, 2021
1 parent 37e296c commit accb818
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/refresh/vkpt/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,13 @@ qerror_t MOD_LoadIQM_RTX(model_t* model, const void* rawdata, size_t length, con
iqm_mesh_t* iqm_mesh = &model->iqmData->meshes[model_idx];
maliasmesh_t* mesh = &model->meshes[model_idx];

mesh->indices = (int*)iqm_mesh->data->indices + iqm_mesh->first_triangle * 3;
mesh->positions = (vec3_t*)(iqm_mesh->data->positions + iqm_mesh->first_vertex * 3);
mesh->normals = (vec3_t*)(iqm_mesh->data->normals + iqm_mesh->first_vertex * 3);
mesh->tex_coords = (vec2_t*)(iqm_mesh->data->texcoords + iqm_mesh->first_vertex * 2);
mesh->tangents = (vec3_t*)(iqm_mesh->data->tangents + iqm_mesh->first_vertex * 3);
mesh->blend_indices = (uint32_t*)(iqm_mesh->data->blend_indices + iqm_mesh->first_vertex * 4);
mesh->blend_weights = (vec4_t*)(iqm_mesh->data->blend_weights + iqm_mesh->first_vertex * 4);
mesh->indices = iqm_mesh->data->indices ? (int*)iqm_mesh->data->indices + iqm_mesh->first_triangle * 3 : NULL;
mesh->positions = iqm_mesh->data->positions ? (vec3_t*)(iqm_mesh->data->positions + iqm_mesh->first_vertex * 3) : NULL;
mesh->normals = iqm_mesh->data->normals ? (vec3_t*)(iqm_mesh->data->normals + iqm_mesh->first_vertex * 3) : NULL;
mesh->tex_coords = iqm_mesh->data->texcoords ? (vec2_t*)(iqm_mesh->data->texcoords + iqm_mesh->first_vertex * 2) : NULL;
mesh->tangents = iqm_mesh->data->tangents ? (vec3_t*)(iqm_mesh->data->tangents + iqm_mesh->first_vertex * 3) : NULL;
mesh->blend_indices = iqm_mesh->data->blend_indices ? (uint32_t*)(iqm_mesh->data->blend_indices + iqm_mesh->first_vertex * 4) : NULL;
mesh->blend_weights = iqm_mesh->data->blend_weights ? (vec4_t*)(iqm_mesh->data->blend_weights + iqm_mesh->first_vertex * 4) : NULL;

mesh->numindices = (int)(iqm_mesh->num_triangles * 3);
mesh->numverts = (int)iqm_mesh->num_vertexes;
Expand Down

0 comments on commit accb818

Please sign in to comment.