Revanth14 opened a new issue, #1869:
URL: https://github.com/apache/iceberg-go/issues/1869

   ### Apache Iceberg version
   
   None
   
   ### Please describe the bug 🐞
   
   ### Apache Iceberg version
   
   main (development)
   
   ### Please describe the bug 
   
   `table.Snapshot.UnmarshalJSON` accepts snapshot JSON when the required 
`snapshot-id` or `timestamp-ms` field is missing or null.
   
   Because both fields are decoded directly into non-pointer `int64` values, 
missing and null values silently become zero:
   
   ```go
   var snapshot table.Snapshot
   
   err := json.Unmarshal([]byte(`{
     "snapshot-id": null,
     "timestamp-ms": 1234,
     "manifests": []
   }`), &snapshot)
   
   // err == nil
   // snapshot.SnapshotID == 0
   ```
   
   The same happens for `timestamp-ms`. A JSON `null` snapshot is also accepted 
and becomes a zero-value `Snapshot`, replacing any value already held by the 
receiver.
   
   This affects the table metadata parse path as well. Removing either field 
from a snapshot in `table/testdata/TableMetadataV2Valid.json` still allows 
`table.ParseMetadata` to succeed. A null entry in the `snapshots` list is also 
accepted when it does not trigger another metadata consistency check.
   
   The Iceberg specification requires both fields for format versions 1–3:
   
   https://iceberg.apache.org/spec/#snapshots
   
   Java rejects the same inputs: `SnapshotParser.fromJson` requires an object 
and reads both fields using `JsonUtil.getLong`, which rejects missing and null 
values:
   
   
https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/SnapshotParser.java
   
   ### Impact
   
   Malformed snapshot metadata is silently assigned default identity and 
timestamp values:
   
   - A missing `snapshot-id` becomes `0` and can be treated as an actual 
snapshot identity.
   - A missing `timestamp-ms` becomes the Unix epoch, potentially affecting 
time-travel resolution, ordering, inspection, and expiration behavior.
   - A null snapshot entry becomes a zero-value snapshot rather than producing 
an error.
   
   The existing metadata validation checks duplicate IDs and reference 
consistency, but cannot determine whether these fields were present in the 
original JSON.
   
   ### Expected behavior
   
   Parsing should return an error wrapping `table.ErrInvalidMetadata` when:
   
   - `snapshot-id` is missing or null.
   - `timestamp-ms` is missing or null.
   - A snapshot document or entry is null.
   
   Explicit numeric zero values should remain distinguishable from missing 
fields and continue to parse. Failed unmarshalling should not partially replace 
an existing `Snapshot` value.
   
   
   ### Willingness to contribute
   
   I can contribute this fix independently.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to