Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JPEG を壊す話 / About JPEG corruption
Search
Shimpei Makimoto
August 18, 2018
Technology
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JPEG を壊す話 / About JPEG corruption
Kyoto.なんか #4
Shimpei Makimoto
August 18, 2018
More Decks by Shimpei Makimoto
See All by Shimpei Makimoto
How to Work with Legacy Ruby on Rails Applications in Treasure Data
makimoto
1
1.6k
Training for New Graduates in Cookpad (Shitei Todan 2015)
makimoto
0
6.2k
How to read code
makimoto
0
1.7k
Glitch, OSS activities, and so on (Oedo RubyKaigi 04 #oedo04)
makimoto
5
1.4k
The Pragmatic Animated GIF in Ruby (a RubyConf 2013 lightning talk)
makimoto
0
590
グリッチについて話をします。 #wedding_s
makimoto
3
590
The Pragmatic Glitch (#rubykaigi 2013 LT)
makimoto
4
3.4k
chiyahoya.me
makimoto
0
360
Recipes of Recipe Search
makimoto
5
1.6k
Other Decks in Technology
See All in Technology
家のリアーキテクト・リファクタリング
suguruooki
0
140
安心して変更できるWebフロントエンドの作り方
pirosikick
4
2.1k
Geolonia の開発現場における AIの活用について
miya0001
0
100
AI 時代のスタートアップエコシステ厶から考究する技術的負債との向き合い方
m3m0r7
PRO
2
1.4k
WAF 運用改善の承認サイクル/SRE_BizReach_MIXI_1
visional_engineering_and_design
2
640
Gitは怖い?共有ワークスペースから始めるSnowflakeチーム開発
coco_se
0
200
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
0
1.8k
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
4
550
Sigmaで作る業務アプリ
kazushiro_honma
0
130
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
1.3k
すぐできる衛星通信対応 あとは山奥に行くだけ
tatetate55
0
120
俺の仕事は AIに奪われないし、たぶんその BIも要らない
hikaruri
0
420
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
990
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
570
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
690
Test your architecture with Archunit
thirion
2
2.4k
Navigating Team Friction
lara
192
16k
How to Ace a Technical Interview
jacobian
281
24k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Building Adaptive Systems
keathley
44
3.2k
Amusing Abliteration
ianozsvald
1
300
Balancing Empowerment & Direction
lara
6
1.3k
Transcript
JPEG を壊す話 Shimpei Makimoto (@makimoto) Kyoto.なんか #4 (18th Aug 2018)
誰? - Shimpei Makimoto - Software Engineer in Tokyo -
自分でも厳密な所属がわからない - https://twitter.com/makimoto - https://github.com/makimoto https://twitter.com/makimoto/status/1027473102437904386
JPEG - Joint Photographic Experts Group https://en.wikipedia.org/wiki/JPEG - 厳密には JPEG
は画像圧縮手法のことを指す - 人間たちが JPEG と呼んでいるのは大体のケースで JPEG を用いて画像をファイ ルに保存するための形式である JFIF (JPEG File Interchange Format) のことを指 す - グリッチの文脈ではもっともロバストな画像フォーマットの1つ
いろいろな画像形式でグリッチを試すデモ - iTerm2 と Docker Hub の makimoto/glitch-playground イメージを使う -
docker run -v /path/to/data:/data \ -i -t makimoto/glitch-playground
何これ? - https://hub.docker.com/r/makimoto/glitch-playground/ - https://github.com/makimoto/glitch-playground - ImageMagick と各種画像処理ライブラリをインストールした Docker コンテナの中
で画像を変換して sed して表示させるスクリプトを動かしている - iTerm2 で動く imgcat を使って表示させている https://www.iterm2.com/documentation-images.html
ロバスト #とは - JPEG 形式の画像は割と壊れない - PNG とか結構すぐ壊れる - GIF
とか WebP とかは割と良い
何故壊れるのか - 壊してはいけない場所を壊す - 雑なヒューリスティックをする手もある https://github.com/makimoto/glitch/blob/9b5b9b3c59fbcddae15e40e2e4cd522964b8749e/commands.go#L98-L102 - (割とちゃんと動くんだけど) 雑すぎ -
ちゃんと画像フォーマットを理解した上で壊せば壊れない
JPEG の仕様とか - https://www.w3.org/Graphics/JPEG/ - https://www.w3.org/Graphics/JPEG/itu-t81.pdf - 画像圧縮手法としての JPEG の仕様
- https://www.w3.org/Graphics/JPEG/jfif3.pdf - 画像フォーマット (JFIF) の仕様 - 読むのが辛い場合は Go のライブラリのコードを追うと良いかも - https://golang.org/pkg/image/jpeg/
xxd -g1 lena.jpg 00000000: ff d8 ff e0 00 10
4a 46 49 46 00 01 01 00 00 01 ......JFIF...... 00000010: 00 01 00 00 ff db 00 43 00 03 02 02 02 02 02 03 .......C........ 00000020: 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 ................ 00000030: 06 05 06 09 08 0a 0a 09 08 09 09 0a 0c 0f 0c 0a ................ 00000040: 0b 0e 0b 09 09 0d 11 0d 0e 0f 10 10 11 10 0a 0c ................ 00000050: 12 13 12 10 13 0f 10 10 10 ff db 00 43 01 03 03 ............C... 00000060: 03 04 03 04 08 04 04 08 10 0b 09 0b 10 10 10 10 ................ 00000070: 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ................ 00000080: (snip)
xxd -g1 lena.jpg 00000000: ff d8 ff e0 00 10
4a 46 49 46 00 01 01 00 00 01 ......JFIF...... 00000010: 00 01 00 00 ff db 00 43 00 03 02 02 02 02 02 03 .......C........ 00000020: 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 ................ 00000030: 06 05 06 09 08 0a 0a 09 08 09 09 0a 0c 0f 0c 0a ................ 00000040: 0b 0e 0b 09 09 0d 11 0d 0e 0f 10 10 11 10 0a 0c ................ 00000050: 12 13 12 10 13 0f 10 10 10 ff db 00 43 01 03 03 ............C... 00000060: 03 04 03 04 08 04 04 08 10 0b 09 0b 10 10 10 10 ................ 00000070: 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ................ 00000080: (snip) SOI APP0 DQT DQT
JPEG - JPEG (JFIF) 内で \xff から始まる値はマーカーとして扱われる - \xff\xd8 -
SOI (Start of Image) - \xff\xe0 - APP0 (Reserved for application segments) - \xff\xdb - DQT (Define quantization table(s))
https://www.w3.org/Graphics/JPEG/itu-t81.pdf
マーカーのプレフィックスを壊すと即死 - ruby -e 'print ARGF.read.b.gsub("\xff".b, "\xfe".b)' lena.jpg > out.jpg
マーカーの後の2バイトの値を壊しても即死 - ruby -e 'print ARGF.read.b.gsub(/(\xff.)[^\xff]./n, "\\1\x00\x00".b)' lena.jpg > out.jpg
- マーカーに続く2バイトは大体各セクションの長さを示すので破壊されると画像が開 けなくなる https://www.w3.org/Graphics/JPEG/itu-t81.pdf
jpegsan.gem - https://rubygems.org/gems/jpegsan - https://github.com/makimoto/jpegsan - ~/misc に転がっていた jpeg.rb を整えてさっき
push した
使用例 [3] pry(main)> jpeg.data[4] => #<struct Jpegsan::Jpeg::JpegMarker code_suffix="\xC0", symbol="SOF0", description="non-differential,
Huffman coding - Baseline DCT", data_sequence="\x00\x11\b\x02\x00\x02\x00\x03\x01\x11\x00\x02\x11\x01\x03\ x11\x01">
使用例 [4] pry(main)> jpeg.data[4].sequence_in_hex => "00 11 08 02 00
02 00 03 01 11 00 02 11 01 03 11 01"
使用例
None
他の例 - に の量子化テーブルを適用
他の例 - に のハフマン符号テーブルを適用
まとめ - 画像フォーマットを考慮して画像を破壊すると安全に壊せるし、逆に完全に壊さな い感じにもできる - フォーマットを意識してやるのはそれなりにコストがかかるのでできるだけ自動化し たいですね
About JPEG corruption Shimpei Makimoto (@makimoto) Kyoto.なんか #4 (18th Aug
2018)