Skip to content

Read SEQ_LEN in ReferenceObj_Read only after a row was read - #283

Open
tfenne wants to merge 1 commit into
ncbi:engineeringfrom
tfenne:fix-reference-read-after-failed-row
Open

tfenne wants to merge 1 commit into
ncbi:engineeringfrom
tfenne:fix-reference-read-after-failed-row

Conversation

@tfenne

@tfenne tfenne commented Sep 25, 2026

Copy link
Copy Markdown

Thank you for maintaining ncbi-vdb. This fixes the segfault described in #282: ReferenceObj_Read() reads the SEQ_LEN cell of a row even when TableReader_ReadRow() failed, which dereferences NULL when no row has been read through the reference list yet.

Change

The SEQ_LEN check that ends the loop at a reference's last row now runs inside if ( rc == 0 ), after the row has been read. On a failed read the loop ends anyway (while ( rc == 0 && ... )), so behaviour is otherwise unchanged.

Testing

On macOS 26.6.1 arm64, Apple clang, against a debug build of engineering, with the harness from the issue on SRR390728 without its references and remote access disabled:

  • Before: references whose first rows aren't in the archive (e.g. NC_000016.8) segfault at reference.c:1030.
  • After: those return rc=0x9be50398 with nothing written; references whose data are present read the same 5,000 bases as before.

No regression test is included, since it needs an aligned archive whose external references are unavailable. I'm happy to add one if you can suggest where.

I dedicate this change to the public domain, consistent with the project's Public Domain Notice. Thanks for considering it; I'm glad to rework it in whatever way you prefer.

When TableReader_ReadRow failed, for example for an external reference
that isn't available, ReferenceObj_Read still read the SEQ_LEN cell of the
row: a stale value if a row of another reference had been read before,
otherwise a NULL dereference. The loop ends on a failed read either way,
so the check now runs only after a successful read.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant