Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
gob バイナリが Go バージョンによって 出力が変わることについて調べてみた / Inve...
Search
convto
September 13, 2024
Technology
0
85
gob バイナリが Go バージョンによって 出力が変わることについて調べてみた / Investigating How gob Binary Output Changes Across Go Versions
Asakusa.go #3 での発表資料です
convto
September 13, 2024
Tweet
Share
More Decks by convto
See All by convto
Go 関連の個人的おもしろCVE 5選 / my favorite go cve
convto
3
370
バイナリを眺めてわかる gob encoding の仕様と性質、適切な使い方 / understanding gob encoding
convto
6
2.4k
みんなでたのしむ math/big / i love math big
convto
0
230
Go1.22からの疑似乱数生成器について/go-122-pseudo-random-generator
convto
2
640
Go1.20からサポートされるtree構造のerrの紹介と、treeを考慮した複数マッチができるライブラリを作った話/introduction of tree structure err added since go 1_20
convto
0
990
byte列のbit表現を得るencodingライブラリ作った
convto
1
1.2k
Go runtimeの歩き方/how to follow go runtime function
convto
1
950
入出金ドメインの苦労話と解決へのアプローチ/funds in/out difficulties and solutions
convto
2
1.3k
rsa_understanding_memo
convto
0
590
Other Decks in Technology
See All in Technology
2/18/25: Java meets AI: Build LLM-Powered Apps with LangChain4j
edeandrea
PRO
0
110
管理者しか知らないOutlookの裏側のAIを覗く#AzureTravelers
hirotomotaguchi
2
380
Goで作って学ぶWebSocket
ryuichi1208
0
160
目の前の仕事と向き合うことで成長できる - 仕事とスキルを広げる / Every little bit counts
soudai
24
7.1k
プロダクトエンジニア構想を立ち上げ、プロダクト志向な組織への成長を続けている話 / grow into a product-oriented organization
hiro_torii
1
170
TAMとre:Capセキュリティ編 〜拡張脅威検出デモを添えて〜
fujiihda
2
240
2.5Dモデルのすべて
yu4u
2
860
次世代KYC活動報告 / 20250219-BizDay17-KYC-nextgen
oidfj
0
250
君も受託系GISエンジニアにならないか
sudataka
2
430
組織貢献をするフリーランスエンジニアという生き方
n_takehata
1
1.3k
利用終了したドメイン名の最強終活〜観測環境を育てて、分析・供養している件〜 / The Ultimate End-of-Life Preparation for Discontinued Domain Names
nttcom
2
190
RSNA2024振り返り
nanachi
0
580
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1368
200k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
Raft: Consensus for Rubyists
vanstee
137
6.8k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
The Cult of Friendly URLs
andyhume
78
6.2k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
Facilitating Awesome Meetings
lara
52
6.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
A Tale of Four Properties
chriscoyier
158
23k
Transcript
gob バイナリが Go バージョンによって 出力が変わることについて調べてみた 2024/09/13 Asakusa.go #3
自己紹介 @convto 株式会社LayerX所属 (読みはこんぶとです)
gob ってなに? - Go が標準パッケージで実装してる独自のエンコーディング! - 仕様とかくわしく知りたい人はこちらをご覧ください https://speakerdeck.com/convto/understanding-gob-encoding - きょうは
5min LT なので全員完全理解者だと思って話を進めます
ある日知人から以下のタレコミをうける
タレコミ - なんか Go のバージョンによって gob の出力が異なるんだけど - marshal/unmarshal 間の互換性はありそう
- どこで変わったんだろうね
確認してみる
確認してみる
None
cnt: 36 id: -64 cnt: 12 id: 64 cnt: 37
id: -65 cnt: 12 id: 65
なんか typedef / value の id がずれてそう - たしかに出力は変わっている -
id の値が変わっている - id = 65 だと typedef がちょうど 1byte で表現できないため、古い方は ちょっと勿体無い - 先頭 1bit が終端判定、末尾 1bit が正負判定。値が 6bit で収まる なら 1byte で表現できる。65 はちょうどたりない
どこで入った? - 霊感で 1.21 まで比べてみたら 1.23 と一致してた $ diff -s
<(go1.21.0 run main.go) <(go1.23.0 run main.go) Files /dev/fd/11 and /dev/fd/12 are identical - 1.20.1 系では挙動に差がない $ diff -s <(go1.20.1 run main.go) <(go1.20.14 run main.go) Files /dev/fd/11 and /dev/fd/12 are identical - 1.21 に上がる時に入っているはず!
見つけた! https://go-review.googlesource.com/c/go/+/460543/4 /src/encoding/gob/type.go#b184
id ずれた理由 - firstUserId = 64 が定義されてて user 定義の型は id
= 64 から始ま る - とりあえず nextId +1 から確保してたのが止まって 64 から使えるように なったという話っぽい!
スッキリ
知人に伝えて平和が訪れた
感想 - marshal/unmarshal の互換を担保した上で encoded な値が変わるこ とはちょいちょいある - よくあるのはフィールド順番担保されないとか。今回は typeid
が揃わな かった - encoded な値に対して一致するか確認する、みたいな処理は秘孔をつく 可能性があるのでやめておきましょう
ご清聴ありがとうございました