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

Calling update with memmapped data can create invalid data in memmap views #1530

Closed
braingram opened this issue Apr 25, 2023 · 1 comment · Fixed by #1668
Closed

Calling update with memmapped data can create invalid data in memmap views #1530

braingram opened this issue Apr 25, 2023 · 1 comment · Fixed by #1668

Comments

@braingram
Copy link
Contributor

If an update causes a memmapped block to be moved, any views taken of the array that uses the block will point to invalid data.

Running the following example code (that adds a large amount of text to the tree to cause the memmapped blocks to be moved):

import asdf
import numpy


fn = 'test.asdf'
a = numpy.zeros(10, dtype='uint8')
b = numpy.ones(10, dtype='uint8')

af = asdf.AsdfFile({'a': a, 'b': b})
af.write_to(fn)

with asdf.open(fn, mode='rw') as af:
    va = af['a'][:3]
    print(f"A: {af['a'][:]}")
    print(f"b: {af['b'][:]}")
    print(f"va: {va}")
    af['c'] = 'a' * 10000
    af.update()
    print(f"A: {af['a'][:]}")
    print(f"b: {af['b'][:]}")
    print(f"va: {va}")

Produces the following output which shows that the view of 'a', here 'va', is incorrect following the update.

A: [0 0 0 0 0 0 0 0 0 0]
b: [1 1 1 1 1 1 1 1 1 1]
va: [0 0 0]
A: [0 0 0 0 0 0 0 0 0 0]
b: [1 1 1 1 1 1 1 1 1 1]
va: [97 97 97]
@braingram
Copy link
Contributor Author

braingram commented Apr 25, 2023

Removal of the source array results in a segfault when the view is accessed.

import asdf
import numpy


fn = 'test.asdf'
a = numpy.zeros(10, dtype='uint8')
b = numpy.ones(10, dtype='uint8')

af = asdf.AsdfFile({'a': a, 'b': b})
af.write_to(fn)

with asdf.open(fn, mode='rw') as af:
    va = af['a'][:3]
    print(f"A: {af['a'][:]}")
    print(f"b: {af['b'][:]}")
    print(f"va: {va}")
    af['c'] = 'a' * 10000
    del af.tree['a']
    del af.tree['b']
    af.update()
    print(f"va: {va}")

results in

A: [0 0 0 0 0 0 0 0 0 0]
b: [1 1 1 1 1 1 1 1 1 1]
va: [0 0 0]
Segmentation fault: 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant