summaryrefslogtreecommitdiff
path: root/lib/stdlib/test/shell_docs_SUITE_data/unknown_erlang_binary_to_term_2_func.txt
blob: 026b8d18cb92f102fd5b831ee289c3dbde0fac73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

  -spec binary_to_term(Binary, Opts) -> term() | {term(), Used}
                          when
                              Binary :: ext_binary(),
                              Opt :: safe | used,
                              Opts :: [Opt],
                              Used :: pos_integer().

Since:
  OTP R13B04

  As binary_to_term/1, but takes these options:

  safe:
    Use this option when receiving binaries from an untrusted
    source.

    When enabled, it prevents decoding data that can be used to
    attack the Erlang system. In the event of receiving unsafe
    data, decoding fails with a badarg error.

    This prevents creation of new atoms directly, creation of new
    atoms indirectly (as they are embedded in certain structures,
    such as process identifiers, refs, and funs), and creation of
    new external function references. None of those resources are
    garbage collected, so unchecked creation of them can exhaust
    available memory.

      > binary_to_term(<<131,100,0,5,"hello">>, [safe]).
      ** exception error: bad argument
      > hello.
      hello
      > binary_to_term(<<131,100,0,5,"hello">>, [safe]).
      hello

  used:
    Changes the return value to {Term, Used} where Used is the
    number of bytes actually read from Binary.

      > Input = <<131,100,0,5,"hello","world">>.
      <<131,100,0,5,104,101,108,108,111,119,111,114,108,100>>
      > {Term, Used} = binary_to_term(Input, [used]).
      {hello, 9}
      > split_binary(Input, Used).
      {<<131,100,0,5,104,101,108,108,111>>, <<"world">>}

  Failure: badarg if safe is specified and unsafe data is
  decoded.

  See also term_to_binary/1, binary_to_term/1, and 
  list_to_existing_atom/1.