NiVO / BY TECHNOGISGermany · Indonesia
Model container tutorial

GLB BIN Padding: Separate Declared Buffer Bytes from Aligned Chunk Length

Inspect an isolated GLB BIN payload against its declared buffer length, retain legitimate zero data, and distinguish container padding from accessor and model validation.

GLB BIN Padding: Separate Declared Buffer Bytes from Aligned Chunk Length

Identify which length is being compared in the handoff

A model handoff diagnostic can report that a GLB binary chunk is slightly longer than the buffer length declared in its JSON. That difference does not automatically establish that the model has unwanted data or that its buffer declaration should be increased. GLB container alignment can account for a short trailing pad. Before editing a drone-related model, identify whether the reported number is the chunk data length, the JSON buffer byteLength, a buffer-view length, or an accessor size. These numbers describe different layers of the representation.

This tutorial examines one already isolated, constructed BIN chunk payload together with its already identified buffer length. It does not open a GLB file, resolve a model graph, read a NiVO asset, or validate geometry. The example demonstrates how to retain declared buffer bytes while recognizing the short container padding allowed by the specification. The accompanying product photograph supplies separate catalogue context. A successful length check should not be presented as evidence that a real model is complete, accurate, self-contained, or accepted for a survey task.

Read the buffer-length allowance and the padding rule together

The Khronos glTF specification states that the GLB-stored BIN chunk may be up to three bytes larger than its JSON-defined buffer.byteLength to satisfy padding requirements. The buffer referring to that chunk is the first buffer and has no uri property. These are contextual rules for identifying the correct data source; a diagnostic must establish that association before comparing lengths. This tutorial assumes that identification has already been performed and does not attempt to infer it from the supplied bytes.

The GLB chunk rules require four-byte alignment, and the BIN chunk uses trailing zero bytes for its padding. The JSON chunk follows a different padding rule using spaces. Do not treat every trailing byte in every chunk as interchangeable padding. For a declared buffer of three bytes inside a four-byte BIN payload, exactly the final byte lies beyond the declared buffer. If the third byte is also zero, it still belongs to the buffer. Its value alone cannot establish that it should be removed.

Restored NiVO VTOL V3 product image from the supplied brochure
Restored NiVO VTOL V3 product image from the supplied brochure.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Inspect a bounded payload without trimming legitimate zeros

Run the Python function below locally. It accepts an immutable byte string and a declared buffer length from one through sixty-four bytes. This small size restriction is a teaching limit, not a glTF format limit. The function checks four-byte payload alignment, rejects a payload shorter than the declared buffer, and limits the extra tail to three bytes. It then verifies that the bytes beyond the declared length are zero. It returns the declared data as hexadecimal plus the padding count, without changing the supplied bytes.

The constructed payload contains hexadecimal 41, 42, 00, and 00, with a declared buffer length of three. The result should preserve data_hex as 414200 and report one padding byte. An indiscriminate trailing-zero removal would instead discard the legitimate third buffer byte. No full GLB header, chunk type, JSON declaration, checksum, accessor, or geometry is parsed here. The function demonstrates one length-and-tail check on inputs that have already been selected by the caller, rather than a complete container reader or asset validator.

def inspect_bin_tail(buffer_byte_length, bin_payload):
    if type(buffer_byte_length) is not int or not 1 <= buffer_byte_length <= 64:
        raise ValueError("Teaching profile requires 1..64 declared buffer bytes")
    if type(bin_payload) is not bytes:
        raise ValueError("Expected an isolated immutable BIN chunk payload")
    if len(bin_payload) % 4:
        raise ValueError("BIN payload length must satisfy four-byte alignment")
    padding = len(bin_payload) - buffer_byte_length
    if not 0 <= padding <= 3:
        raise ValueError("BIN length must cover the buffer with at most three pad bytes")
    if any(bin_payload[buffer_byte_length:]):
        raise ValueError("BIN padding bytes must be zero")
    return {"declared_bytes": buffer_byte_length,
            "chunk_bytes": len(bin_payload),
            "padding_bytes": padding,
            "data_hex": bin_payload[:buffer_byte_length].hex()}

# Constructed BIN payload; the first zero is declared data.
print(inspect_bin_tail(3, bytes.fromhex("41 42 00 00")))

Treat inconsistent lengths as findings rather than repair instructions

A payload that is shorter than the declared buffer cannot supply all the bytes that this declaration requests. A tail longer than three bytes is outside the specific allowance being checked. Nonzero bytes beyond the declared length also fail this limited BIN padding check. Preserve those observations and the original bytes rather than extending a declaration, adding guessed zeros, or deleting a tail until the function passes. Such edits could conceal a wrong input selection, an incomplete read, or a problem that belongs elsewhere in the container.

An exactly aligned buffer can require no additional padding at all. Test that case independently from a three-byte buffer with one padding byte. Also test a one-byte buffer with three padding bytes and a declared buffer ending in several legitimate zeros. These examples expose the difference between an offset boundary determined by metadata and a pattern guessed from byte values. A zero scan cannot replace the declared boundary, even when its output happens to look plausible for one simple teaching payload.

Keep container padding separate from model data layout

The padding discussed here is at the end of the GLB BIN chunk. It is not the same as matrix column padding, accessor stride, or spacing between buffer views. A model reader must still follow each relevant declaration when interpreting the bytes inside the buffer. Do not use the returned padding count as an accessor stride or assume that every internal zero is unused. The small function deliberately leaves all declared buffer bytes untouched, without assigning them a component type or a geometric meaning.

Likewise, a matching length and zero tail do not prove that the GLB has a correct header, ordered chunks, valid JSON, supported extensions, complete referenced resources, or suitable geometry. A real asset may require additional files or interpretation beyond this isolated payload. Establish a comparable stage when investigating differences between applications: one tool may show the aligned chunk while another shows only the declared buffer. Those displays can differ in length without proving that either tool changed the underlying model content.

Deliver a precise buffer-boundary explanation

For a real model investigation, retain the received asset identity, container version, selected BIN chunk, relevant buffer index and uri state, JSON buffer.byteLength, chunk data length, tail bytes, and reader version. Record which checks identified the association and which checks examined only the isolated payload. Include a small independently verified byte range that preserves zeros inside the declared buffer. If another validation step was performed, keep its method and result separate instead of allowing this narrow check to imply broader acceptance.

In a NiVO-related model handoff, this approach can explain a small length discrepancy without inventing a product export capability or a measured survey outcome. Another reviewer can reproduce why four chunk bytes contain three declared buffer bytes and one padding byte in the constructed example. Preserve the original asset and continue the independent checks for structure, data layout, dependencies, geometry, and intended use. The useful result is an auditable boundary between data and allowed container padding, with the scope of that conclusion clearly attached.

When a comparison report displays only a byte total, request or retain the label defining that total before trying a conversion. The same word length can refer to the complete file, a chunk including its header, the chunk payload, or the declared glTF buffer. This function expects only the BIN payload, excluding its chunk header. Making that input contract explicit prevents a correct padding rule from being applied at the wrong boundary and producing a misleading failure.

Technical references

  1. Khronos glTF: GLB-stored buffer and the three-byte length allowance ↗
  2. Khronos glTF: GLB chunk alignment and binary buffer padding ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team