update corrupts stream data
Closed this issue · 0 comments
braingram commented
Calling update on a file with a Stream corrupts the data.
There are probably 2 separate issues here (as commented in the example below):
- accessing the stream after the update results in a segfault
- the updated file contains invalid data
The invalid written data occurs as far back as ASDF 2.8 (the segfault was only tested with 2.15). Prior to 2.8 (tested in 2.7 and 2.6) the data is also invalid but reads as all 0s instead of the odd values.
import asdf
import numpy
fn = 'stream.asdf'
s = asdf.Stream([3], numpy.uint8)
asdf.AsdfFile({'s': s}).write_to(fn)
with open(fn, 'rb+') as f:
f.seek(0, 2)
f.write(b'\x01\x02\x03')
with asdf.open(fn) as af:
numpy.testing.assert_array_equal(af['s'], [[1, 2, 3]])
with asdf.open(fn, mode='rw') as af:
af['a'] = numpy.arange(1000)
af.update()
# print(af['s']) # segmentation fault
with asdf.open(fn) as af:
# fails as af['s'] == [[116, 101, 111]]
numpy.testing.assert_array_equal(af['s'], [[1, 2, 3]])