SystemError while execing bad code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gerrit Holl

    SystemError while execing bad code

    Hi,

    I found a cool way to trigger a SystemError:
    [color=blue][color=green][color=darkred]
    >>> exec CodeType(0,0,0, 0,"",(),(),()," ","",0,"")[/color][/color][/color]
    XXX lineno: 0, opcode: 0
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.2/site-packages/", line 0, in
    File "/usr/lib/python2.2/site-packages/", line 0, in
    SystemError: unknown opcode

    The documentation says:
    You should report this to the author or maintainer of your Python
    interpreter. Be sure to report the version of the Python interpreter
    (sys.version; it is also printed at the start of an interactive Python
    session), the exact error message (the exception's associated value) and
    if possible the source of the program that triggered the error.

    Although it probably shouldn't be taken literally in this case...
    ....or should it :-)?

    Hmm, and this actually *hangs*:[color=blue][color=green][color=darkred]
    >>> exec CodeType(0,0,0, 0,"",(),(),()," ","",2**31-1,"")[/color][/color][/color]
    XXX lineno: 2147483647, opcode: 0
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.2/site-packages/", line 2147483647, in

    ....

    But I guess this is a case of "so don't do it" :-)?

    yours,
    Gerrit.

    --
    263. If he kill the cattle or sheep that were given to him, he shall
    compensate the owner with cattle for cattle and sheep for sheep.
    -- 1780 BC, Hammurabi, Code of Law
    --
    PrePEP: Builtin path type

    Asperger's Syndrome - a personal approach:


  • Peter Hansen

    #2
    Re: SystemError while execing bad code

    Gerrit Holl wrote:[color=blue]
    >
    > I found a cool way to trigger a SystemError:
    >[color=green][color=darkred]
    > >>> exec CodeType(0,0,0, 0,"",(),(),()," ","",0,"")[/color][/color]
    > XXX lineno: 0, opcode: 0
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > File "/usr/lib/python2.2/site-packages/", line 0, in
    > File "/usr/lib/python2.2/site-packages/", line 0, in
    > SystemError: unknown opcode
    >
    > The documentation says:
    > You should report this to the author or maintainer of your Python
    > interpreter. Be sure to report the version of the Python interpreter
    > (sys.version; it is also printed at the start of an interactive Python
    > session), the exact error message (the exception's associated value) and
    > if possible the source of the program that triggered the error.
    >
    > Although it probably shouldn't be taken literally in this case...
    > ...or should it :-)?
    >
    > Hmm, and this actually *hangs*:[color=green][color=darkred]
    > >>> exec CodeType(0,0,0, 0,"",(),(),()," ","",2**31-1,"")[/color][/color]
    > XXX lineno: 2147483647, opcode: 0
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > File "/usr/lib/python2.2/site-packages/", line 2147483647, in
    >
    > ...
    >
    > But I guess this is a case of "so don't do it" :-)?[/color]

    I once experimented, briefly, with doing "genetic programming" (evolving
    programs to solve problems) using Python bytecode. In effect, this meant
    that random sequences of bytes were being executed as though they were
    valid compiled Python programs.

    The interpreter crashed rapidly and frequently. I quickly concluded
    that the interpreter is designed to be safe in executing bytecode that
    is generated by a proper Python compiler, and that the compiler did not
    generate random bytecodes most of the time.

    Had to abandon that idea, though in principle it's still very cool.

    -Peter

    Comment

    • Michael Hudson

      #3
      Re: SystemError while execing bad code

      Gerrit Holl <gerrit@nl.linu x.org> writes:
      [color=blue]
      > Hi,
      >
      > I found a cool way to trigger a SystemError:[/color]

      How about marshal.loads(' 0') ?
      [color=blue][color=green][color=darkred]
      > >>> exec CodeType(0,0,0, 0,"",(),(),()," ","",0,"")[/color][/color]
      > XXX lineno: 0, opcode: 0
      > Traceback (most recent call last):
      > File "<stdin>", line 1, in ?
      > File "/usr/lib/python2.2/site-packages/", line 0, in
      > File "/usr/lib/python2.2/site-packages/", line 0, in
      > SystemError: unknown opcode[/color]
      [snippety][color=blue]
      > But I guess this is a case of "so don't do it" :-)?[/color]

      Definitely. It's easy enought to crash the interpreter this way
      (think LOAD_CONST 30000, for just one easy way).

      Cheers,
      mwh

      --
      Very clever implementation techniques are required to implement this
      insanity correctly and usefully, not to mention that code written
      with this feature used and abused east and west is exceptionally
      exciting to debug. -- Erik Naggum on Algol-style "call-by-name"

      Comment

      • Skip Montanaro

        #4
        Re: SystemError while execing bad code


        Gerrit> exec CodeType(0,0,0, 0,"",(),(),()," ","",0,"")
        ...
        Gerrit> But I guess this is a case of "so don't do it" :-)?

        Michael> Definitely. It's easy enought to crash the interpreter this
        Michael> way (think LOAD_CONST 30000, for just one easy way).

        In fact, help(types.Code Type) describes it thusly:

        Create a code object. Not for the faint of heart.

        Should this sort of stuff be published on the Wiki?

        Skip

        Comment

        • Michael Hudson

          #5
          Re: SystemError while execing bad code

          Skip Montanaro <skip@pobox.com > writes:
          [color=blue]
          > Gerrit> exec CodeType(0,0,0, 0,"",(),(),()," ","",0,"")
          > ...
          > Gerrit> But I guess this is a case of "so don't do it" :-)?
          >
          > Michael> Definitely. It's easy enought to crash the interpreter this
          > Michael> way (think LOAD_CONST 30000, for just one easy way).
          >
          > In fact, help(types.Code Type) describes it thusly:
          >
          > Create a code object. Not for the faint of heart.
          >
          > Should this sort of stuff be published on the Wiki?[/color]

          I don't understand what you're suggesting here.

          Cheers,
          mwh

          --
          Python enjoys making tradeoffs that drive *someone* crazy <wink>.
          -- Tim Peters, comp.lang.pytho n

          Comment

          Working...