Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: Index exceeds dimension bound #904

Merged
merged 2 commits into from Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nc3internal.h
Expand Up @@ -212,7 +212,7 @@ extern int
NC_findvar(const NC_vararray *ncap, const char *name, NC_var **varpp);

extern int
NC_check_vlen(NC_var *varp, size_t vlen_max);
NC_check_vlen(NC_var *varp, unsigned long long vlen_max);

extern int
NC_lookupvar(NC3_INFO* ncp, int varid, NC_var **varp);
Expand Down
2 changes: 1 addition & 1 deletion libsrc/nc3internal.c
Expand Up @@ -702,7 +702,7 @@ NC_check_vlens(NC3_INFO *ncp)
/* maximum permitted variable size (or size of one record's worth
of a record variable) in bytes. This is different for format 1
and format 2. */
size_t vlen_max;
unsigned long long vlen_max;
size_t ii;
size_t large_vars_count;
size_t rec_vars_count;
Expand Down
6 changes: 3 additions & 3 deletions libsrc/var.c
Expand Up @@ -513,16 +513,16 @@ out :
* systems with LFS it should be 2^32 - 4.
*/
int
NC_check_vlen(NC_var *varp, size_t vlen_max) {
size_t prod=varp->xsz; /* product of xsz and dimensions so far */
NC_check_vlen(NC_var *varp, unsigned long long vlen_max) {
unsigned long long prod=varp->xsz; /* product of xsz and dimensions so far */

int ii;

assert(varp != NULL);
for(ii = IS_RECVAR(varp) ? 1 : 0; ii < varp->ndims; ii++) {
if(!varp->shape)
return 0; /* Shape is undefined/NULL. */
if (varp->shape[ii] > vlen_max / prod) {
if (varp->shape[ii] > (size_t)(vlen_max / prod)) {
return 0; /* size in bytes won't fit in a 32-bit int */
}
prod *= varp->shape[ii];
Expand Down