三日連続。これまでちと色々無理しすぎたかも。
入力と出力について考えないといかんねえ。
久しぶりに焼肉を堪能。
池袋のジュンク堂に某イベントの参加登録をしたついでに先行販売されていたものを購入
(本当は順序は逆)
ANSI C/ISO C99対応と表紙にあるのだけど、C11が決まった後だけにちと残念な気がしないでもない。
まあC11がどうなるか(普及するか)はわかんないけど
一通り読んだあとでまた何か書くかも。
例によって先越されてますが
javascript - Can you explain why ++[[]][+[]]+[+[]] = 10 - Stack Overflow
++[[]][+[]]+[+[]]
is valid and return "10" in JavaScript (more example here: http://sla.ckers.org/forum/read.php?24,33349,33405 ).
これは JavaScript として vaild なもので、「10」を返します
Can you explain why? I don't understand what's happening here.
なぜそうなるのかを説明できますか?
わたしは何が起こっているのか理解できませんでした。
Start by understanding that +[] casts an empty array to 0... then waste an afternoon... ;)
+[] が空の配列を 0 にキャストしているのを理解することから始めましょう。
そのあとは、午後の時間を使って潰して… :)
Related stackoverflow.com/questions/4170978/explain-why-this-works .
If we split it up, the mess is equal to:
そのへんてこなものを分割できるなら次のものと等価です
++[[]][+[]]
+
[+[]]
In JavaScript, it is true that +[] === 0. + converts something into a number, and in
this case it will come down to +"" or 0 (see specification details below).
JavaScript では +[] === 0 は真であり、+ はなにか (something) を数値へと変換します。
そして今回の例の場合、+"" か 0 になります
Therefore, we can simplify it (++ has precendence over +):
したがって、このように単純化できます(++ は + よりも優先順位が高い):
++[[]][0]
+
[0]
Because [[]][0] means: get the first element from [[]], it is true that:
[[]][0] は [[]] の先頭の要素を得ることを意味しますから、以下のことが成り立ちます
[[]][0] returns the inner array ([]). Due to references it's wrong to say [[]][0] === [],
but let's call the inner array A to avoid wrong notation.
[[]][0] は内側にある配列 [] を返します。
[[]][0] === [] とすることは間違っていますが、この内部配列を間違った記法を使わずに
A と呼ぶことにしましょう。
++[[]][0] == A + 1, since ++ means 'increment by one'.
++ は "1増やす"ことなので、 ++[[]][0] == A + 1 です。
++[[]][0] === +(A + 1); in other words, it will always be a number (+1 does not necessarily
return a number, whereas ++ always does - thanks to Tim Down for pointing this out).
別の表現をすると ++[[]][0] === +(A + 1) です。
これは常に数値となります
(+1 は数値を返すのに必須ではありませんが、++ は常に必要です
これを指摘してくれた Tim Down に感謝)
Again, we can simplify the mess into something more legible. Let's substitute [] back for A:
繰り返しますが、例のコードはより legible な単純なものにできます。
A を [] に戻してみましょう
+([] + 1)
+
[0]
In JavaScript, this is true as well: [] + 1 === "1", because [] == "" (joining an empty array), so:
JavaScript では [] == "" (空配列の join) なので [] + 1 は "1" となります。
+([] + 1) === +("" + 1), and
+("" + 1) === +("1"), and
+("1") === 1
Let's simplify it even more:
さらに単純にしましょう
1
+
[0]
Also, this is true in JavaScript: [0] == "0", because it's joining an array
with 1 element. Joining will concatenate the elements separated by ,. With one element,
you can deduce that this logic will result in the first element itself.
JavaScript では [0] == "0" が真です。なぜならひとつの要素を持った配列の join だからです。
join は , で区切って複数の要素を連結するものです。
要素がひとつの場合、これは第一要素それ自身となるロジックを deduce できます。
So, in the end we obtain (number + string = string):
ですから最終的にはこうなります (数値 + 文字列 = 文字列)
1
+
"0"
=== "10" // Yay!
Specification details for +[]:
+[] に関する仕様の詳細
This is quite a maze, but to do +[], first it is being converted to a string because that's what + says:
11.4.6 Unary + Operator (単項の+演算子)
The unary + operator converts its operand to Number type.
The production UnaryExpression : + UnaryExpression is evaluated as follows:
Let expr be the result of evaluating UnaryExpression.
Return ToNumber(GetValue(expr)).
ToNumber() says:
Object
Apply the following steps:
以下の手順を適用します:
Let primValue be ToPrimitive(input argument, hint String).
Return ToString(primValue).
ToPrimitive() says:
Object
Return a default value for the Object. The default value of an object is retrieved by
calling the [[DefaultValue]] internal method of the object, passing the optional hint
PreferredType. The behaviour of the [[DefaultValue]] internal method is defined by this
specification for all native ECMAScript objects in 8.12.8.
[[DefaultValue]] says:
8.12.8 [[DefaultValue]] (hint)
When the [[DefaultValue]] internal method of O is called with hint String, the following
steps are taken:
Let toString be the result of calling the [[Get]] internal method of object O with
argument "toString".
If IsCallable(toString) is true then,
a. Let str be the result of calling the [[Call]] internal method of toString, with O as
the this value and an empty argument list.
b. If str is a primitive value, return str.
The .toString of an array says:
15.4.4.2 Array.prototype.toString ( )
When the toString method is called, the following steps are taken:
Let array be the result of calling ToObject on the this value.
Let func be the result of calling the [[Get]] internal method of array with
argument "join".
If IsCallable(func) is false, then let func be the standard built-in method
Object.prototype.toString (15.2.4.2).
Return the result of calling the [[Call]] internal method of func providing array
as the this value and an empty arguments list.
So +[] comes down to +"", because [].join() === "".
Again, the + is defined as:
11.4.6 Unary + Operator
The unary + operator converts its operand to Number type.
The production UnaryExpression : + UnaryExpression is evaluated as follows:
Let expr be the result of evaluating UnaryExpression.
Return ToNumber(GetValue(expr)).
ToNumber is defined for "" as:
The MV of StringNumericLiteral ::: [empty] is 0.
So +"" === 0, and thus +[] === 0.
>jsshell
js> +[]
0
js> ++[[]][+[]]+[+[]]
10
js>
おー、本当だ。
これもすぐにいろいろなところが詳しく解説したりするでしょう
Cryptanalysis » Effective DoS attacks against Web Application Plattforms – #hashDoS [UPDATE2]
Effective DoS attacks against Web Application Plattforms – #hashDoS [UPDATE2]
December 28th, 2011 Erik Tews Leave a comment Go to comments
Julian Wälde (zeri) and Alexander Klink (alech) presented a very nice way how to bring
down many popular websites at 28C3. The idea is quiet simple, effective and general.
Many programming languages, especially scripting languages, frequently use hash tables
to store all kinds of data.
略
Copyright © 2007-2011 Cryptanalysis