Skip to content

fix github issue #121 - correct bitmap stride in QR code generation#136

Open
munzzyy wants to merge 1 commit into
guardianproject:mainfrom
munzzyy:fix-qr-code-bitmap-stride
Open

fix github issue #121 - correct bitmap stride in QR code generation#136
munzzyy wants to merge 1 commit into
guardianproject:mainfrom
munzzyy:fix-qr-code-bitmap-stride

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 5, 2026

Copy link
Copy Markdown

Fixes #121.

encodeAsBitmap() in SocialImageUtil.kt builds the pixel array using w/h, the actual dimensions zxing's MultiFormatWriter hands back from BitMatrix, and fills it with offset = y * w per row. But the call to bitmap.setPixels() right after passes width (the size that was originally requested) as the stride argument instead of w.

Those two aren't guaranteed to match. QR codes only come in fixed module counts, so MultiFormatWriter.encode() can return a BitMatrix sized slightly differently than what was asked for. Whenever that happens, setPixels() reads each row starting width entries apart in the array while the data is actually laid out w entries apart, so every row past the first is read from the wrong offset. The result is a bitmap where all but the first row of the QR code is shifted, which is exactly the "doesn't render any data" / unscannable symptom in the issue.

Changed the stride argument to w so it matches how the array was actually populated.

Couldn't run this on-device (no Android SDK/emulator in this environment), but the bug is a plain array-indexing mismatch and the fix is checkable by inspection: pixels is written with row stride w, so setPixels needs to be told the row stride is w too. There's no existing test target for this class in app/src/main, so I didn't add one - happy to if there's a preferred place for app-module unit tests here.

…de generation

setPixels() was passed width (the requested dimension) as the row
stride instead of w (the actual BitMatrix width returned by zxing).
Since the pixel array is filled using w as the row stride, any
mismatch between width and w shifts every row after the first,
corrupting the QR code so it can't be scanned.
@n8fr8

n8fr8 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thanks for the fix... I think #121 is actually something else (the image hadn't been uploaded yet to ipfs storage, and so there wasn't a proper URI in the QR code, jus as hash:foo value), but this is still a good bug find anyhow.

@n8fr8 n8fr8 self-assigned this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Social Media Share QR Code doesn't render any data

2 participants