Skip to content

fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding (#973)#973

Open
kewang1024 wants to merge 1 commit into
facebookincubator:mainfrom
kewang1024:export-D112307835
Open

fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding (#973)#973
kewang1024 wants to merge 1 commit into
facebookincubator:mainfrom
kewang1024:export-D112307835

Conversation

@kewang1024

@kewang1024 kewang1024 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary:

preserveDictionaryEncoding propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — values_ is nullptr.

Add isStringType check so only string RLEs enter dict mode.

Differential Revision: D112307835

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 16, 2026
@meta-codesync

meta-codesync Bot commented Jul 16, 2026

Copy link
Copy Markdown

@kewang1024 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112307835.

@meta-codesync meta-codesync Bot changed the title fix(encoding): Handle dict mode in RLEEncoding materialize, readWithVisitor, and bulkScan fix(encoding): Handle dict mode in RLEEncoding materialize, readWithVisitor, and bulkScan (#973) Jul 17, 2026
kewang1024 pushed a commit to kewang1024/nimble that referenced this pull request Jul 17, 2026
…isitor, and bulkScan (facebookincubator#973)

Summary:

CONTEXT: When `readWithDictionary` calls `ensureLoaded(preserveDictionaryEncoding=true)` on a non-dict-convertible string column (e.g., TrivialEncoding), inner RLEEncoding enters dict mode (`dictValues_` set, `values_` nullptr). The flat path then calls `materialize()`, `readWithVisitor()`, or `bulkScan()`, all of which called `advanceRunValue()` without checking which mode the RLE is in. `advanceRunValue()` dereferences `values_` (nullptr in dict mode), causing SIGSEGV or producing garbage values.

How this happens — `readWithDictionary` entry for non-dict columns:
1. Session properties enabled → enters `readWithDictionary`
2. `ensureLoaded(preserveDictionaryEncoding=true)` loads the chunk. The flag propagates to all encodings in the tree, but only RLEEncoding checks it: if inner values encoding is dictionary-enabled, RLE stores as `dictValues_` (dict mode) instead of `values_` (flat mode).
3. `dictionaryConvertible()` returns false (e.g., TrivialEncoding) → returns false → flat path
4. Flat path reads from the encoding loaded with `true`. Inner RLEs are in dict mode.

Two crash variants observed:
- SIGSEGV in `RLEEncoding::materialize()`: `advanceRunValue()` dereferences nullptr `values_` directly.
- SIGSEGV in `TrivialEncoding::readWithVisitor()` at `StringView` construction: `materialize()` fills the lengths buffer with stale `currentValue_` (never updated in dict mode) → garbage lengths → `pos_` drifts to invalid address.

RLEEncoding has two value-storage modes, determined at construction:
- Flat mode (`values_` set): `advanceRunValue()` resolves via `values_->nextValue()`.
- Dict mode (`dictValues_` set): `advanceRunIndex()` gets the dictionary index, then `alphabet_[currentIndex_]` resolves the actual value.
The mode is detectable at runtime by checking `dictValues_ != nullptr`.

Only `skip()` already handled both modes. `materialize()`, `readWithVisitor()`, and `bulkScan()` all assumed flat mode.

WHAT: Add a dict-aware `advanceRun()` override in `RLEEncoding` that checks `dictValues_ != nullptr` to dispatch to the correct advance method, and resolves `currentValue_` from the dictionary in dict mode. All three affected methods now call this single `advanceRun()` instead of inline `advanceRunValue()` calls. In flat mode (the common case), `advanceRun()` takes the else branch and calls `advanceRunValue()` — identical behavior to before.

Differential Revision: D112307835
@meta-codesync meta-codesync Bot changed the title fix(encoding): Handle dict mode in RLEEncoding materialize, readWithVisitor, and bulkScan (#973) fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding Jul 18, 2026
kewang1024 pushed a commit to kewang1024/nimble that referenced this pull request Jul 18, 2026
… in RLEEncoding (facebookincubator#973)

Summary:

`preserveDictionaryEncoding` propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — `values_` is nullptr.

Add `isStringType` check so only string RLEs enter dict mode.

Differential Revision: D112307835
@meta-codesync meta-codesync Bot changed the title fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding fix(encoding): Scope preserveStringDictionaryEncoding to string types in RLEEncoding (#973) Jul 18, 2026
kewang1024 pushed a commit to kewang1024/nimble that referenced this pull request Jul 18, 2026
… in RLEEncoding (facebookincubator#973)

Summary:

`preserveDictionaryEncoding` propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — `values_` is nullptr.

Add `isStringType` check so only string RLEs enter dict mode.

Differential Revision: D112307835
… in RLEEncoding (facebookincubator#973)

Summary:

`preserveDictionaryEncoding` propagates to all RLEs in the encoding tree, putting non-string RLEs (e.g., uint32_t length streams) in dict mode. The flat path then crashes — `values_` is nullptr.

Add `isStringType` check so only string RLEs enter dict mode.

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

Labels

CLA Signed This label is managed by the Meta Open Source bot. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant