package main // The images spec's mutations (§6): each named risk broken on purpose, // and the gate that must notice. IMG1's four, IMG3's, IMG7's copies, // the owner check §6's table names, sealing before Put (IMG2), and one // per walker (IMG5). const ( imagesRead = "internal/mapa/images_read.go" imagesRender = "internal/mapa/images_render.go" imagesAttach = "internal/mapa/images_attach.go" imagesCopies = "internal/mapa/images_copies.go" imagesStore = "internal/mapa/images_store.go" history = "internal/mapa/history.go" walkerJPEG = "internal/mapa/imagefile/jpeg.go" walkerPNG = "internal/mapa/imagefile/png.go" walkerWebP = "internal/mapa/imagefile/webp.go" walkerGIF = "internal/mapa/imagefile/gif.go" inside = "./internal/mapa/" walkers = "./internal/mapa/imagefile/" imgOne = "TestIMG1ImagesLeakNothing" imgTwo = "TestImagesReachTheDiskSealed" imgFive = "TestCleanStripsEveryCanary" attaching = "TestACommitAttachesOnlyItsOwnIntroducedImages" ) // The copies' rules, and their breaks: any page's images, not the // one's. const ( attachedOnly = "\t\tquery = query.Where(\"page_id = ?\", pageID)" attachedAnywhere = "\t\tquery = query.Where(\"page_id != ?\", -pageID)" movedOnly = "\t\tquery = query.Where(\"(page_id = ? OR " + "moved_from = ?)\"" movedAnywhere = "\t\tquery = query.Where(\"(page_id != -? OR " + "moved_from = ?)\"" ) var imageMutations = []mutation{ {gate: "IMG1", test: imgOne, name: "GET /i/{id} drops its scope check", edits: []edit{{file: imagesRead, from: "\t\tWhere(store.readScope(database, member)).", to: "\t\tWhere(\"1 = 1\")."}}}, {gate: "IMG1", test: imgOne, name: "drawing resolves images attached to other pages", edits: []edit{{file: imagesRender, from: "\tshown := entry.page != 0 && entry.page == page", to: "\tshown := entry.page != 0"}}}, {gate: "IMG1", test: "TestAnasOwnCommitOfAPlantedIDAttachesNothing", pkg: inside, name: "attach ignores \"introduced\"", edits: []edit{{file: imagesAttach, from: "\t\tif !held[id] {", to: "\t\tif held != nil {"}}}, {gate: "IMG1", test: "TestAnasRevertToBosTextAttachesNothing", pkg: inside, name: "Revert passes attach", edits: []edit{{file: history, from: "VerbReverted, attachNothing)", to: "VerbReverted, attachOwn(0))"}}}, {gate: "IMG1", test: "TestAnasRestoreOfBosPageAttachesNothing", pkg: inside, name: "Restore passes attach", edits: []edit{{file: aliases, from: "\t\tpage, err := tx.create(KindPage, RungTeam, actor, " + "record, actor,\n\t\t\tVerbRestored, attachNothing)", to: "\t\tpage, err := tx.create(KindPage, RungTeam, actor, " + "record, actor,\n\t\t\tVerbRestored, attachOwn(0))"}}}, {gate: "IMG7", test: attaching, pkg: inside, name: "attaching without the owner check", edits: []edit{{file: imagesAttach, from: "\"page_id IS NULL AND owner_id = ?\", introduced, actor)", to: "\"page_id IS NULL AND owner_id != ?\", introduced, -1)"}}}, {gate: "IMG7", pkg: inside, test: "TestMakeTeamPageCopiesOnlyImagesAttachedToItsSource", name: "Make team page copies an image not attached to its source", edits: []edit{{file: imagesCopies, from: attachedOnly, to: attachedAnywhere}}}, {gate: "IMG7", test: "TestADeletedPagesDraftKeepsOnlyItsOwnPagesImages", pkg: inside, name: "draftToScratch copies an image attached to another page", edits: []edit{{file: imagesCopies, from: movedOnly, to: movedAnywhere}}}, {gate: "IMG2", test: imgTwo, name: "images are Put unsealed", edits: []edit{{file: imagesStore, from: "\tblob, err := store.sealer.SealPadded(seal.PurposeImage, " + "plain)", to: "\tblob, err := seal.Pad(plain), error(nil)"}}}, {gate: "IMG3", test: gateEight, name: "an upload logs no event", edits: []edit{{file: imagesStore, from: "\t\treturn tx.log(actor, ObjectImage, row.ID, " + "VerbUploaded, 0)", to: "\t\treturn nil"}}}, {gate: "IMG6", test: "TestIMG6TheUploadsMapaRefuses", name: "an image may be 20 MB", edits: []edit{{file: "internal/mapa/images.go", from: "\tMaxImageBytes = 10 << 20", to: "\tMaxImageBytes = 20 << 20"}}}, {gate: "IMG6", test: "TestIMG6AWaitForASlotAnswers503", name: "the blob semaphore admits everyone", edits: []edit{{file: store, from: "\tstore.images.slots = make(chan struct{}, BlobSlots)", to: "\tstore.images.slots = make(chan struct{}, " + "100*BlobSlots)"}}}, {gate: "M2", test: "TestAGIFFrameStaysInsideItsScreen", pkg: walkers, name: "a GIF frame may lie past its logical screen", edits: []edit{{file: walkerGIF, from: "\tif left+width > screen[0] || top+height > screen[1] {", to: "\tif left+width > 1<<20 || top+height > 1<<20 {"}}}, {gate: "IMG5", test: imgFive, pkg: walkers, name: "the JPEG walker keeps comments", edits: []edit{{file: walkerJPEG, from: "\tcase marker == markerCOM:\n\t\treturn\n", to: "\tcase marker == markerCOM:\n"}}}, {gate: "IMG5", test: imgFive, pkg: walkers, name: "the JPEG walker keeps what follows EOI", edits: []edit{{file: walkerJPEG, from: "\treturn append(out, 0xff, markerEOI), " + "walk.orientation, nil", to: "\treturn append(append(out, 0xff, markerEOI), " + "walk.raw[len(out):]...), walk.orientation, nil"}}}, {gate: "IMG5", test: imgFive, pkg: walkers, name: "the PNG walker keeps text chunks", edits: []edit{{file: walkerPNG, from: "\t\"bKGD\": true, \"acTL\": true,", to: "\t\"bKGD\": true, \"tEXt\": true, \"acTL\": true,"}}}, {gate: "IMG5", test: imgFive, pkg: walkers, name: "the WebP walker keeps EXIF", edits: []edit{{file: walkerWebP, from: "\t\"ANMF\": true, \"ICCP\": true,", to: "\t\"ANMF\": true, \"ICCP\": true, \"EXIF\": true,"}}}, {gate: "IMG5", test: imgFive, pkg: walkers, name: "the GIF walker keeps every application extension", edits: []edit{{file: walkerGIF, from: "\t\treturn next, netscapeLoop(raw[at:next]), false, nil", to: "\t\treturn next, nil, true, nil"}}}, }