LALFrame memory allocation behaviour is inconsistent on non-x86_64
The behaviour of XLALFrStreamReadINT4TimeSeries
(and the same for other types) when given invalid input is inconsistent depending on the platform, principally x86_64 vs non-x86_64.
On x86_64 attempting to allocate an array of negative size results in a Memory allocation error
(which I think is expected), but on arm64 (macOS and Linux) and ppc64le the result is a valid INT4Vector
with no data.
How to reproduce
The below outputs execute the following python snippet attempting to read -1 seconds of data from one of the test GWF files in the lalframe/test
directory.:
import lalframe
stream = lalframe.FrStreamOpen('lalframe/test', 'F-TEST-600000000-60.gwf')
series = lalframe.FrStreamReadINT4TimeSeries(stream, 'H1:LSC-AS_Q', 600000000, -1, 0)
Observed behaviours
Behaviour 1 (RuntimeError
)
$ uname -a
Linux WR14F6D8F62EF8 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
$ conda list lalframe
# packages in environment at /home/duncan/opt/mambaforge/envs/py312:
#
# Name Version Build Channel
liblalframe 3.0.4 h8fba346_1 conda-forge
python-lalframe 3.0.4 py312hc7c0aa3_1 conda-forge
$ python --version
Python 3.12.2
$ python
Python 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lalframe
>>> stream = lalframe.FrStreamOpen('lalframe/test', 'F-TEST-600000000-60.gwf')
>>> series = lalframe.FrStreamReadINT4TimeSeries(stream, 'H1:LSC-AS_Q', 600000000, -1, 0)
XLALError - XLALReallocLong in /home/conda/feedstock_root/build_artifacts/lal-split_1711636675768/work/lib/tools/Sequence_source.c:125XLAL Error - XLALReallocLong (/home/conda/feedstock_root/build_artifacts/lal-split_1711636675768/work/lib/std/LALMalloc.c:109): Memory allocation error
XLAL Error - XLALResizeINT4Sequence (/home/conda/feedstock_root/build_artifacts/lal-split_1711636675768/work/lib/tools/Sequence_source.c:134): Internal function call failed: Memory allocation error
XLAL Error - XLALResizeINT4TimeSeries (/home/conda/feedstock_root/build_artifacts/lal-split_1711636675768/work/lib/tools/TimeSeries_source.c:110): Internal function call failed: Memory allocation error
XLAL Error - XLALFrStreamReadINT4TimeSeries (/home/conda/feedstock_root/build_artifacts/lalframe-split_1711652535256/work/lib/LALFrStreamReadTS_source.c:230): Internal function call failed: Memory allocation error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Internal function call failed: Memory allocation error
Behaviour 2 (no error)
$ uname -a
Darwin builder-osx-6.ligo.org 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103 arm64
$ sw_vers
ProductName: macOS
ProductVersion: 14.5
BuildVersion: 23F79
$ conda list lalframe
# packages in environment at /Users/duncanmacleod/opt/mambaforge/envs/lalframe:
#
# Name Version Build Channel
liblalframe 3.0.4 h3363767_1 conda-forge
python-lalframe 3.0.4 py312hf635c46_1 conda-forge
$ python --version
Python 3.12.4
$ python
Python 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lalframe
>>> stream = lalframe.FrStreamOpen('lalframe/test', 'F-TEST-600000000-60.gwf')
>>> series = lalframe.FrStreamReadINT4TimeSeries(stream, 'H1:LSC-AS_Q', 600000000, -1, 0)
>>> print(series)
<Swig Object of type 'tagINT4TimeSeries *' at 0x10484f970>
>>> print(series.data)
<Swig Object of type 'tagINT4Vector *' at 0x104888a70>
>>> print(series.data.length, series.data.data)
0 None
Passing the same test through the conda-forge builds for LALFrame shows the following results
Platform | Result |
---|---|
Linux x86_64 | Failure (Behaviour 1) |
Linux aarch64 (ARM) | No failure (Behaviour 2) |
Linux ppc64le | No failure |
macOS x86_64 | Failure |
I have no particular opinion on what the 'right response' should be, but would love to see consistent behaviour on all platforms.
cc @jolien-creighton (author of the code in question)