The Sunset That Crashed the Phone

Easy

· Frontend

Incident

SEV-1

BUG-WALLPAPER

Priority: Critical (crash loop) · reported by device QA

Time to fix: 10 min

Failing checks on the shipped build

  • a pixel just above 255 is counted in the top bin

    Index 256 out of bounds for length 256

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 value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  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

Android · 2020

Modelled on the Android wallpaper crash of 2020. A photograph of a lake at sunset, shared widely online, put some Android phones into a crash loop when it was set as the wallpaper. The image used a wide-gamut colour space; after conversion, a pixel's computed luminance rounded up to 256 and was used to index a 256-entry histogram — one past the end. System UI crashed on every start until the wallpaper was removed. The fix clamped the value to the histogram's range.

Histogram.java builds the luminance histogram System UI uses to pick light or dark status-bar icons. Converted pixels arrive on the 0–255 scale but can land slightly outside it.

Fix build so every pixel lands in a valid bin.

Code map

class Histogram {
    static final int BINS = 256;

    static int[] build(double[][] pixels) {
        int[] bins = new int[BINS];
        for (double[] px : pixels) {
            int y = (int) Math.round(Luminance.of(px));
            bins[y]++;
        }
        return bins;
    }
}

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.

The Sunset That Crashed the Phone — Java Bug Hunt

Modelled on the Android wallpaper crash of 2020. A photograph of a lake at sunset, shared widely online, put some Android phones into a crash loop when it…

  • Language: Java
  • Layer: Frontend
  • Difficulty: Easy
  • Concepts: Overflow, Bounds
  • Modelled on: Android · 2020
  • Visible tests: black and white land in the end bins; a pixel just above 255 is counted in the top bin
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (crash loop))
  • Ticket: BUG-WALLPAPER
  • Reported by: device QA
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • a pixel just above 255 is counted in the top bin — Index 256 out of bounds for length 256

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 value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  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

Modelled on the Android wallpaper crash of 2020. A photograph of a lake at sunset, shared widely online, put some Android phones into a crash loop when it was set as the wallpaper. The image used a wide-gamut colour space; after conversion, a pixel's computed luminance rounded up to 256 and was used to index a 256-entry histogram — one past the end. System UI crashed on every start until the wallpaper was removed. The fix clamped the value to the histogram's range.

Histogram.java builds the luminance histogram System UI uses to pick light or dark status-bar icons. Converted pixels arrive on the 0–255 scale but can land slightly outside it.

Fix build so every pixel lands in a valid bin.

Bug report

BUG-WALLPAPER · Priority: Critical (crash loop) · Reported by: device QA

Histogram.build(pixels) returns int[256]:

  • each pixel's luminance is Luminance.of(px), rounded to the nearest integer
  • a value above 255 counts in bin 255; a value below 0 counts in bin 0
  • every pixel is counted exactly once (the bins sum to pixels.length)

Observed: ArrayIndexOutOfBoundsException: Index 256 out of bounds for length 256 when the sunset photo is set as wallpaper.

Logs

E AndroidRuntime: FATAL EXCEPTION: main  Process: com.android.systemui
E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: length=256; index=256
I ActivityManager: Process com.android.systemui has died (restart 7)

The code as shipped

src/ui/Histogram.java (editable)

class Histogram {
    static final int BINS = 256;

    static int[] build(double[][] pixels) {
        int[] bins = new int[BINS];
        for (double[] px : pixels) {
            int y = (int) Math.round(Luminance.of(px));
            bins[y]++;
        }
        return bins;
    }
}

Read-only context: src/ui/Luminance.java.

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 Java bug hunts.