Fix 32-bit integer overflow in AllOutData byte calculation#3373
Open
andrew-platt wants to merge 2 commits into
Open
Fix 32-bit integer overflow in AllOutData byte calculation#3373andrew-platt wants to merge 2 commits into
andrew-platt wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes misleading negative byte-count values caused by 32-bit integer overflow in allocation error messages, and adds an early guard in FAST_InitOutput to fail fast with a clear, actionable message when the in-memory binary output buffer would exceed ~2 GB.
Changes:
- Updates NWTC
AllocAry-style allocation error messages (2D–5D variants shown) to compute byte counts using 64-bit integer arithmetic. - Adds a pre-allocation size check for
AllOutDatainFAST_InitOutputto prevent oversized in-memory binary output allocations and provide user guidance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| modules/openfast-library/src/FAST_Subs.f90 | Adds a 64-bit pre-check for AllOutData buffer size and aborts early with an actionable error message when exceeding the in-memory binary limit. |
| modules/nwtc-library/src/NWTC_IO.f90 | Prevents 32-bit overflow in allocation error-message byte-count calculations by casting dimensions to 64-bit integers before multiplication. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The AllocAry routines in NWTC_IO.f90 computed the byte count for error messages using 32-bit integer arithmetic (AryDim1*AryDim2*BYTES_IN_RxKi), which overflowed for large arrays, producing misleading negative values in error messages. Changes: - NWTC_IO.f90: Cast all dimension arguments to B8Ki before multiplication in error message byte-count calculations for all multi-dimensional AllocAry routines (2D through 5D, integer, R4Ki, and R8Ki variants). - FAST_Subs.f90: Add pre-allocation safeguard in FAST_InitOutput that computes the AllOutData array size using B8Ki arithmetic and checks against a 2 GB limit before attempting allocation. Provides a clear error message with the required memory size, array dimensions, and actionable suggestions (reduce TMax, increase DT_Out, reduce output channels, or use text output format). Co-authored-by: Andy Platt <andrew-platt@users.noreply.github.com> Co-authored-by: Claude Opus 4 <noreply@anthropic.com>
Co-authored-by: GitHub Copilot <support@github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
b17e6a5 to
bb615bc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ready to merge pending review
Feature or improvement description
Fix 32-bit integer overflow in the
AllOutDatabinary output buffer byte-count calculation, and add a pre-allocation safeguard with an actionable error message.When
(NumOuts-1) * NOutSteps * BYTES_IN_RxKiexceeds ~2.1 GB, the 32-bit integer arithmetic inAllocAryerror messages overflowed, producing confusing negative byte counts (e.g.,-1501695564 bytes). This commonly occurs with smallDT_Outvalues (orDT_Outdefaulting toDT) combined with long simulation times (e.g.,DT=0.0002,TMax=6400s→ 32 million output steps).This PR:
B8Ki(64-bit integer) before multiplication in the NWTC library'sAllocAryerror messages (all 2D–5D variants).FAST_InitOutputthat computes the requiredAllOutDatasize using 64-bit arithmetic and fails early with a clear message including the required memory, array dimensions, and user-actionable suggestions.Related issue, if one exists
#3371
Impacted areas of the software
modules/nwtc-library/src/NWTC_IO.f90— All multi-dimensionalAllocAryroutines (error message byte-count calculations)modules/openfast-library/src/FAST_Subs.f90—FAST_InitOutputsubroutine (binary output buffer allocation)Additional supporting information
Example error before this fix:
Example error after this fix:
The checkpoint save/restore code (
RegPackAlloc/RegUnpackAlloc) stores array bounds as individualB4Kivalues per dimension and uses Fortran native I/O for data, so it is unaffected by this change and correctly handles large arrays on 64-bit systems.Generative AI usage
This PR was substantially generated with AI assistance for analysis, diagnosis, and implementation:
Co-authored-by: Anthropic Claude claude@anthropic.com
Assisted by: GitHub Copilot support@github.com
Estimated resource usage for this session:
Test results, if applicable
nwtclibsandopenfastlibwith gfortran on aarch64 Linux).