Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
6cf08d25
Unverified
Commit
6cf08d25
authored
Mar 28, 2024
by
Raul
Committed by
GitHub
Mar 28, 2024
Browse files
Avoid overflow in large XTC files (#4485)
* Avoid overflow in large XTC files * Also cast box indices to size_t
parent
f82876f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
15 deletions
+17
-15
wrappers/python/openmm/app/internal/xtc_utils/src/xtc.cpp
wrappers/python/openmm/app/internal/xtc_utils/src/xtc.cpp
+17
-15
No files found.
wrappers/python/openmm/app/internal/xtc_utils/src/xtc.cpp
View file @
6cf08d25
...
...
@@ -123,20 +123,21 @@ void xtc_read(std::string filename, float* coords_arr, float* box_arr, float* ti
throw
std
::
runtime_error
(
"xtc_read(): natoms is 0
\n
"
);
}
XDRFILE_RAII
xd
(
filename
,
"r"
);
int
fidx
=
0
;
size_t
fidx
=
0
;
size_t
nframes_long
=
nframes
;
XTCFrame
frame
(
natoms
);
while
(
exdrOK
==
frame
.
readNextFrame
(
xd
))
{
time_arr
[
fidx
]
=
frame
.
time
;
step_arr
[
fidx
]
=
frame
.
step
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
for
(
int
j
=
0
;
j
<
3
;
j
++
)
{
box_arr
[
fidx
+
(
3
*
i
+
j
)
*
nframes
]
=
frame
.
box
[
i
][
j
];
box_arr
[
fidx
+
(
3
*
i
+
j
)
*
nframes
_long
]
=
frame
.
box
[
i
][
j
];
}
}
for
(
in
t
aidx
=
0
;
aidx
<
natoms
;
aidx
++
)
{
in
t
xidx
=
Xf
(
aidx
,
fidx
,
nframes
);
in
t
yidx
=
Yf
(
xidx
,
nframes
);
in
t
zidx
=
Zf
(
yidx
,
nframes
);
for
(
size_
t
aidx
=
0
;
aidx
<
natoms
;
aidx
++
)
{
size_
t
xidx
=
Xf
(
aidx
,
fidx
,
nframes
_long
);
size_
t
yidx
=
Yf
(
xidx
,
nframes
_long
);
size_
t
zidx
=
Zf
(
yidx
,
nframes
_long
);
coords_arr
[
xidx
]
=
frame
.
positions
[
3
*
aidx
+
0
];
coords_arr
[
yidx
]
=
frame
.
positions
[
3
*
aidx
+
1
];
coords_arr
[
zidx
]
=
frame
.
positions
[
3
*
aidx
+
2
];
...
...
@@ -145,9 +146,9 @@ void xtc_read(std::string filename, float* coords_arr, float* box_arr, float* ti
}
}
static
void
box_from_array
(
matrix
&
matrix_box
,
float
*
box
,
in
t
frame
,
in
t
nframes
)
{
for
(
in
t
i
=
0
;
i
<
3
;
i
++
)
{
for
(
in
t
j
=
0
;
j
<
3
;
j
++
)
{
static
void
box_from_array
(
matrix
&
matrix_box
,
float
*
box
,
size_
t
frame
,
size_
t
nframes
)
{
for
(
size_
t
i
=
0
;
i
<
3
;
i
++
)
{
for
(
size_
t
j
=
0
;
j
<
3
;
j
++
)
{
matrix_box
[
i
][
j
]
=
box
[(
3
*
i
+
j
)
*
nframes
+
frame
];
}
}
...
...
@@ -156,12 +157,13 @@ static void box_from_array(matrix& matrix_box, float* box, int frame, int nframe
void
xtc_write
(
std
::
string
filename
,
int
natoms
,
int
nframes
,
int
*
step
,
float
*
timex
,
float
*
pos
,
float
*
box
)
{
XDRFILE_RAII
xd
(
filename
,
"a"
);
XTCFrame
frame
(
natoms
);
for
(
int
f
=
0
;
f
<
nframes
;
f
++
)
{
box_from_array
(
frame
.
box
,
box
,
f
,
nframes
);
for
(
int
i
=
0
;
i
<
natoms
;
i
++
)
{
int
xidx
=
Xf
(
i
,
f
,
nframes
);
int
yidx
=
Yf
(
xidx
,
nframes
);
int
zidx
=
Zf
(
yidx
,
nframes
);
size_t
nframes_long
=
nframes
;
for
(
size_t
f
=
0
;
f
<
nframes
;
f
++
)
{
box_from_array
(
frame
.
box
,
box
,
f
,
nframes_long
);
for
(
size_t
i
=
0
;
i
<
natoms
;
i
++
)
{
size_t
xidx
=
Xf
(
i
,
f
,
nframes_long
);
size_t
yidx
=
Yf
(
xidx
,
nframes_long
);
size_t
zidx
=
Zf
(
yidx
,
nframes_long
);
frame
.
positions
[
3
*
i
+
0
]
=
pos
[
xidx
];
frame
.
positions
[
3
*
i
+
1
]
=
pos
[
yidx
];
frame
.
positions
[
3
*
i
+
2
]
=
pos
[
zidx
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment