MerginMaps / MerginMaps/geodiff

GEODIFF_rebase assigns negative FIDs when sqlite_sequence.seq exceeds INT32_MAX

Open
#251 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug data corruption - sync failure - crash
Dominant language
Python
Stars
183
Forks
21
Avg merge
9d 11h
Merged PRs (30d)
2

Description

When two devices concurrently add features to a GeoPackage layer and one needs to rebase against the other's changes, the rebased device's new features receive negative FIDs. The root cause is a silent narrowing cast from int64_t to int (32-bit) in the rebase code, which corrupts FID values whenever sqlite_sequence.seq exceeds INT32_MAX (2,147,483,647).

This was observed in a real project where sqlite_sequence.seq had grown to 77,194,629,200 — well beyond INT32_MAX. The table itself contained only 244 rows (FIDs 1–244), but the high-water mark in sqlite_sequence persisted from a prior operation. With 8 devices collecting data simultaneously, every device except the first to sync received negative FIDs for all newly added features. The pattern was fully deterministic: first sync → positive FIDs, all subsequent syncs → negative FIDs.

Note that sqlite_sequence is intentionally excluded from geodiff changesets (https://github.com/MerginMaps/geodiff/blob/master/geodiff/src/drivers/sqlitedriver.cpp#L232), which means a corrupted seq value is not visible to geodiff and cannot be corrected via normal (diff) sync.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in geodiff/src/drivers/sqlitedriver.cpp, including the sqlite_sequence handling around line 232, and trace the rebase path that assigns new feature IDs. Reproduce a rebase with sqlite_sequence.seq above INT32_MAX and verify that newly added features receive positive, non-corrupted FIDs without changing the intended exclusion from changesets.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, sqlite
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.