taylorfinnell / awscr-s3

A Crystal shard for S3.
https://taylorfinnell.github.io/awscr-s3/
MIT License
81 stars 48 forks source link

Abort if the response is not well-formed XML #108

Open BrucePerens opened 2 years ago

BrucePerens commented 2 years ago

https://github.com/taylorfinnell/awscr-s3/blob/36c0f3bd03bbf3bc577da4b9eae3fccc0d61e3c3/src/awscr-s3/xml.cr#L48 aborts in not_nil! if the response is not well-formed XML.

Unhandled exception: Nil assertion failed (NilAssertionError)
  from /usr/share/crystal/src/nil.cr:108:5 in 'not_nil!'
  from lib/awscr-s3/src/awscr-s3/xml.cr:48:9 in 'namespaces'
  from lib/awscr-s3/src/awscr-s3/xml.cr:39:12 in 'namespace'
  from lib/awscr-s3/src/awscr-s3/xml.cr:29:14 in 'build_path'
  from lib/awscr-s3/src/awscr-s3/xml.cr:11:21 in 'string'
  from lib/awscr-s3/src/awscr-s3/xml.cr:53:33 in 'Awscr::S3::XML#string<String>:String'
  from lib/awscr-s3/src/awscr-s3/exceptions.cr:88:7 in 'from_response'
  from lib/awscr-s3/src/awscr-s3/http.cr:114:9 in 'handle_response!'
  from lib/awscr-s3/src/awscr-s3/http.cr:88:16 in 'exec'
  from lib/awscr-s3/src/awscr-s3/http.cr:46:7 in 'put'
  from lib/awscr-s3/src/awscr-s3/client.cr:243:7 in 'put_object'
  from lib/awscr-s3/src/awscr-s3/file_uploader.cr:34:9 in 'upload'
BrucePerens commented 2 years ago

And how did I get there? It's this bug: https://github.com/crystal-lang/crystal/issues/11354 The response body starts with the gzip magic number. But in any case awscr-s3 should be robust against poorly-formatted responses.