Skip to content

xilinx: writeBitstream silently emits a zero data-length field on non-seekable output and never reports write errors #40

Description

@lromor

BitstreamWriter::writeBitstream (fpga/xilinx/bitstream-writer.h:159-188) was refactored from an ofstream-by-path to a generic std::ostream, and backpatches the 4-byte e (data length) record via tellp() / seekp(). It returns 0 unconditionally.

assembler.cc passes std::cout:

  • With fpga-as ... > out.bit the stream is seekable and everything works.
  • Through a pipe (fpga-as ... | prog) or a terminal, tellp() returns -1, seekp() sets failbit, the length field silently stays 0x00000000, and the tool still reports success.
  • Stream write errors (disk full, EPIPE) are likewise never detected. The prjxray original at least returned 1 when the output file could not be opened.

Consumers that honor the e TLV length see a data length of 0.

Fix options: buffer the payload and write the length up front; or check out state after the final seekp/put sequence and return an error; or require a seekable stream explicitly.

Found by comparing against prjxray @ 7557c7cc.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions