Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Custom exercises: an animated GIF meets the photo's pixel guard, and a JPEG's frame header is found behind large APP segments
Duarte Santos0415aa68a645
diff --git a/frontend/src/lib/media-ingest.js b/frontend/src/lib/media-ingest.jsindex c3798f4f7..3de826803 100644--- a/frontend/src/lib/media-ingest.js+++ b/frontend/src/lib/media-ingest.js@@ -8,7 +8,8 @@* miss a field. Before decoding, the header's pixel count is checked: a 100-megapixel photo* would need several hundred MB just to open.* - A GIF keeps its frames and loses its comment and metadata blocks (media-sniff cleanGif). A- * GIF of one frame is a photo and goes down that path.+ * GIF of one frame is a photo and goes down that path; an animation is held to the photo's+ * pixel guard on its logical screen.* - An MP4/MOV keeps its video and sound; its metadata boxes and the samples of any track that is* neither (timed metadata, GPS telemetry) are zeroed in place (media-sniff scrubMp4). A WebM is* kept as it is — its scrub is deferred, and the docs say so.@@ -119,7 +120,11 @@ async function photo(file, sniffed, limits, deps) {if (file.size > limits.rawPhotoMB * MB) throw new MediaError('too-large', { mb: limits.rawPhotoMB })if (!sniffed.input) {const head = new Uint8Array(await file.slice(0, 256 * 1024).arrayBuffer())- const d = imageDims(head)+ let d = imageDims(head)+ // A JPEG's frame header can sit behind APP segments bigger than that (a camera's maker notes,+ // an embedded preview); the check that comes after the decode would come too late to save+ // the memory, so the whole file — at most rawPhotoMB — is read for it instead.+ if (!d && sniffed.mime === 'image/jpeg' && file.size > head.length) d = imageDims(new Uint8Array(await file.arrayBuffer()))if (d && d.width * d.height > MAX_PHOTO_MP * 1e6) throw new MediaError('photo-too-big')}const pic = await deps.decodeImage(file, sniffed.mime, deps)@@ -139,6 +144,9 @@ async function gif(file, limits, deps) {const info = inspectGif(bytes)if (!info) throw new MediaError('unreadable')if (info.frames === 1) return photo(new Blob([bytes], { type: 'image/gif' }), { mime: 'image/gif' }, limits, deps)+ // The same pixel guard as a photo's, on the logical screen, before the poster's decode — and+ // before every device that shows it decodes the animation at full size.+ if (info.width * info.height > MAX_PHOTO_MP * 1e6) throw new MediaError('photo-too-big')let cleantry { clean = cleanGif(bytes) } catch { throw new MediaError('unreadable') }const main = { blob: new Blob([clean], { type: 'image/gif' }), mime: 'image/gif', width: info.width, height: info.height }diff --git a/frontend/src/lib/media-ingest.test.js b/frontend/src/lib/media-ingest.test.jsindex bd56ca0a5..310aa2b59 100644--- a/frontend/src/lib/media-ingest.test.js+++ b/frontend/src/lib/media-ingest.test.js@@ -49,6 +49,15 @@ describe('photos', () => {expect(d.decodeImage).not.toHaveBeenCalled()})+ it('finds the frame header of a JPEG behind more than 256 KB of APP segments, and refuses it before decoding', async () => {+ const d = deps()+ const app = () => bytes([0xff, 0xe2], [0xff, 0xff], fill(0xffff - 2)) // one full-length APP2 segment+ const big = jpeg(9000, 7000)+ const padded = bytes(big.subarray(0, 2), app(), app(), app(), app(), app(), big.subarray(2))+ await expect(ingestMediaFile(file(padded), LIMITS, d)).rejects.toMatchObject({ code: 'photo-too-big' })+ expect(d.decodeImage).not.toHaveBeenCalled()+ })+it('refuses a raw photo over its cap, and steps the quality down before refusing an encoded one', async () => {await expect(ingestMediaFile(file(bytes(jpeg(), fill(41 * MB))), LIMITS, deps())).rejects.toMatchObject({ code: 'too-large', mb: 40 })const d = deps({ encodeImage: vi.fn(async (pic, edge) => ({ blob: new Blob([new Uint8Array(3 * MB)]), mime: 'image/webp', width: edge, height: edge })) })@@ -92,6 +101,13 @@ describe('GIFs', () => {expect(out.media).toMatchObject({ kind: 'image', mime: 'image/webp' })})+ it('refuses an animation over 52 megapixels on its header, before decoding a frame', async () => {+ const d = deps()+ const g = gif({ w: 16000, h: 16000, blocks: [gce(10), frame(1, 1), gce(10), frame(1, 1)] })+ await expect(ingestMediaFile(file(g), LIMITS, d)).rejects.toMatchObject({ code: 'photo-too-big' })+ expect(d.decodeImage).not.toHaveBeenCalled()+ })+it('refuses one over the GIF cap', async () => {await expect(ingestMediaFile(file(bytes(gif(), fill(9 * MB))), LIMITS, deps())).rejects.toMatchObject({ code: 'too-large', mb: 8 })})