-
Notifications
You must be signed in to change notification settings - Fork 383
Ensure the buffer provided to MPAS_io_get_var_generic is large enough. #1367
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
base: develop
Are you sure you want to change the base?
Conversation
3d97db2 to
d610024
Compare
d610024 to
7f2f3a8
Compare
mgduda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jim-p-w I've verified that the changes to mpas_io.F catch cases where we would otherwise have tried to read a string into a buffer that was too small. If you could rework the commit history so that it contains just a couple of commits -- perhaps one to modify the framework mpas_io code, and another to add unit tests -- I think we'll be ready to merge this.
|
@mgduda Is the initial commit message in the PR suitable for the framework commit? Or do you have suggestions/edits you would prefer to see? |
A fixed size array is provided as an input buffer when reading 0d-char character variables. Call MPAS_io_inq_var prior to the read to get the size of the variable’s value, and only proceed with the read if the variable’s value will fit in the provided array. Return an error code if the variable’s value is larger than the provided input buffer.
Character variables are read into fixed size arrays when reading netcdf files. A test is added which tries to read character variables into a buffer which isn't large enough to hold the data. The test verifies the read fails with a suitable error code.
7b258f4 to
9bdcede
Compare
This PR fixes a potential buffer overrun when reading string variables from a netcdf file.
A fixed size array is provided as an output buffer when reading a 0d-char character variable.
Call MPAS_io_inq_var prior to the read to get the size of the variable, and only proceed with the read if the size of the variable will fit in the provided array.
Return an error code if the variable value is larger than the provided output buffer.
A unit test is included to verify:
Fixes issue #1350
Note
When building with PIO, if the charArray (or the charArray1d) value exceeds the size of the tempchar buffer provided to the call to
PIO_get_var, the value will be truncated to the size of the provided tempchar buffer (lines 2018, 2023, and 2042 in src/framework/mpas_io.F).