Half an Emoji in the Username

Medium

· Database

Incident

SEV-2

BUG-MB4

Priority: High · reported by storage

Time to fix: 20 min

Failing checks on the shipped build

  • the result never exceeds the byte budget

    budget is bytes, not characters: expected a truthy value but got false

  • multi-byte characters are kept whole

    é costs two bytes: expected "h\u00e9ll" but got "h\u00e9llo"

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the data through the query or the repository code; compare the rows it returns with the rows the report expects.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

MySQL utf8

Inspired by MySQL's legendary utf8-that-isn't (3 bytes max — real UTF-8 needs utf8mb4), and the truncation bugs that slice multi-byte characters in half on the way into a column.

truncate.py fits a username into a byte budget. It must never split a character.

Code map

# Fits text into a UTF-8 byte budget without corrupting characters.

def fit_bytes(text, max_bytes):
    return text[:max_bytes]

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

Half an Emoji in the Username — Python Bug Hunt

Inspired by MySQL's legendary utf8-that-isn't (3 bytes max — real UTF-8 needs utf8mb4), and the truncation bugs that slice multi-byte characters in half on…

  • Language: Python
  • Layer: Database
  • Difficulty: Medium
  • Concepts: Unicode, Encoding
  • Modelled on: MySQL utf8
  • Visible tests: ascii within budget is untouched; the result never exceeds the byte budget; multi-byte characters are kept whole
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-MB4
  • Reported by: storage
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • the result never exceeds the byte budget — budget is bytes, not characters: expected a truthy value but got false
  • multi-byte characters are kept whole — é costs two bytes: expected "h\u00e9ll" but got "h\u00e9llo"

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the data through the query or the repository code; compare the rows it returns with the rows the report expects.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Inspired by MySQL's legendary utf8-that-isn't (3 bytes max — real UTF-8 needs utf8mb4), and the truncation bugs that slice multi-byte characters in half on the way into a column.

truncate.py fits a username into a byte budget. It must never split a character.

Bug report

BUG-MB4 · Priority: High · Reported by: storage

fit_bytes(text, max_bytes):

  • the UTF-8 encoding of the result is at most max_bytes long
  • characters are kept whole — a 4-byte emoji that doesn't fit is dropped
  • keep the longest valid prefix

Observed: slicing by characters overflows the byte budget, and the write path then hard-truncates mid-emoji, corrupting the row.

Logs

[db] value for column 'display_name' exceeds byte limit; hard-truncated
[render] username shows U+FFFD replacement character

The code as shipped

src/db/truncate.py (editable)

# Fits text into a UTF-8 byte budget without corrupting characters.

def fit_bytes(text, max_bytes):
    return text[:max_bytes]

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.