Skip to content

Flag collision in cbf.h #113

Description

@dwpaley

MSG_DIGESTWARN (a read-mode flag) and PAD_1K (write-mode) share a common bit 0x0020. This doesn't appear to be causing any problems, but it could be a latent headache and appears easy enough to fix. Claude will give the details:

Affected: CBFlib 0.9.8 (and current HEAD) — include/cbf.h:637-640

Two distinct header flags are #defined with the same value:

#define MSG_DIGESTWARN  0x0020   /* warn on digest mismatch — used on the READ path  */
#define PAD_1K          0x0020   /* pad binary section with 1023 nulls — WRITE path  */

PAD_2K (0x0040) and PAD_4K (0x0080) do not currently collide; only PAD_1K aliases MSG_DIGESTWARN.

Impact — latent, not a functional bug in normal use

MSG_DIGESTWARN is tested against file->read_headers (read path) and PAD_1K against file->write_headers (write path, src/cbf_write_binary.c:330-336). These are separate words, so ordinary read/write flows are unaffected. But the shared numeric value is a footgun: any code that builds or inspects a combined flag word, reuses one value across read+write, or reasons about the flags as one family (as the documentation does) will conflate "warn-on-digest" with "1 KB padding."

Suggested fix

Reassign PAD_1K to a free bit not used by the MIME_*/MSG_* read flags (mind the CBF_PARSE_* bits starting at 0x0100), or, if the read/write separation is intentional, document it explicitly at the definitions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions