summaryrefslogtreecommitdiff
path: root/lib/stdlib/test/shell_docs_SUITE_data/unknown_erlang_binary_to_term_2_func.txt
blob: 60e6109348c0c58782055757b67b907e27fe92ff (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
52
53
54
55
56
57
58
59

  -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 runtime. 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

    Warning:
      The safe option ensures the data is safely processed by
      the Erlang runtime but it does not guarantee the data is
      safe to your application. You must always validate data
      from untrusted sources. If the binary is stored or
      transits through untrusted sources, you should also
      consider cryptographically signing it.

  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.