Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java XmlSaxPushParser raises odd error when buffer overflows #567

Closed
samuelkadolph opened this issue Nov 14, 2011 · 5 comments
Closed

java XmlSaxPushParser raises odd error when buffer overflows #567

samuelkadolph opened this issue Nov 14, 2011 · 5 comments

Comments

@samuelkadolph
Copy link

When you push a string into the Nokogiri::XML::Sax::PushParser that is over 512 characters you get an odd syntax error instead of an error about the buffer overflowing.

require "nokogiri"

class Parser < Nokogiri::XML::SAX::Document
end

xml = <<-XML
<CreateApplicationVersionResponse xmlns="http://elasticbeanstalk.amazonaws.com/docs/2010-12-01/">
  <CreateApplicationVersionResult>
    <ApplicationVersion>
      <SourceBundle>
        <S3Bucket>elasticbeanstalk-us-east-1-516445455037</S3Bucket>
        <S3Key>2011-11-14-omega-2a74f431c50ce2d30d72dcc16616aa7596e6f85d.war</S3Key>
      </SourceBundle>
      <VersionLabel>1.0.0.alpha12</VersionLabel>
      <ApplicationName>omega</ApplicationName>
      <DateCreated>2011-11-14T20:49:20.332Z</DateCreated>
pad
XML

puts xml.size

parser = Parser.new
pusher = Nokogiri::XML::SAX::PushParser.new(parser)
pusher << xml
pusher.finish
513
Nokogiri::XML::SyntaxError: Element type "Cre" must be followed by either attribute specifications, ">" or "/>".
  native_write at nokogiri/XmlSaxPushParser.java:149
         write at /Users/i822055/.rvm/gems/jruby-1.6.5/gems/nokogiri-1.5.0-java/lib/nokogiri/xml/sax/push_parser.rb:47
        (root) at xml2.rb:24

This works fine with the c version of nokogiri.
https://github.com/tenderlove/nokogiri/blob/v1.5.0/ext/java/nokogiri/internals/PushInputStream.java#L79

@yokolet
Copy link
Member

yokolet commented Nov 15, 2011

I see. There's a limit of 512. I'll have a look.

@samuelkadolph
Copy link
Author

I've given up on using the push parser since it's so utterly broken for jruby for dealing with chunked data.

require "nokogiri"

include Nokogiri::XML::SAX

xml = <<-XML
<CreateApplicationVersionResponse xmlns="http://elasticbeanstalk.amazonaws.com/docs/2010-12-01/">
  <CreateApplicationVersionResult>
    <ApplicationVersion>
      <SourceBundle>
        <S3Bucket>elasticbeanstalk-us-east-1-516445455037</S3Bucket>
        <S3Key>2011-11-14-omega-2a74f431c50ce2d30d72dcc16616aa7596e6f85d.war</S3Key>
      </SourceBundle>
      <VersionLabel>1.0.0.alpha12</VersionLabel>
      <ApplicationName>omega</ApplicationName>
      <DateCreated>2011-11-14T20:49:20.332Z</DateCreated>
    </ApplicationVersion>
  </CreateApplicationVersionResult>
</CreateApplicationVersionResponse>
XML

pusher = PushParser.new(Document.new)
pusher << xml[0,512]
pusher << xml[512,512]
pusher.finish

# ArrayList.java:547:in `RangeCheck': java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
#   from ArrayList.java:322:in `get'
#   from PushInputStream.java:372:in `put'
#   from PushInputStream.java:94:in `write'
#   from PushInputStream.java:105:in `writeAndWaitForRead'
#   from XmlSaxPushParser.java:124:in `native_write'
#   from XmlSaxPushParser$i$2$0$native_write.gen:65535:in `call'
#   from CachingCallSite.java:332:in `cacheAndCall'
#   from CachingCallSite.java:203:in `call'
#   from FCallTwoArgNode.java:38:in `interpret'
#   from NewlineNode.java:104:in `interpret'
#   from ASTInterpreter.java:75:in `INTERPRET_METHOD'
#   from InterpretedMethod.java:190:in `call'
#   from DefaultMethod.java:179:in `call'
#   from AliasMethod.java:61:in `call'
#   from CachingCallSite.java:312:in `cacheAndCall'
#   from CachingCallSite.java:169:in `call'
#   from ShiftLeftCallSite.java:24:in `call'
#   from xml.rb:22:in `__file__'
#   from xml.rb:-1:in `load'
#   from Ruby.java:693:in `runScript'
#   from Ruby.java:686:in `runScript'
#   from Ruby.java:593:in `runNormally'
#   from Ruby.java:442:in `runFromMain'
#   from Main.java:321:in `doRunFromMain'
#   from Main.java:241:in `internalRun'
#   from Main.java:207:in `run'
#   from Main.java:191:in `run'
#   from Main.java:171:in `main'

@yokolet
Copy link
Member

yokolet commented Nov 15, 2011

I'm sorry about push parser. Pure Java version of push parser needs to be improved a lot. There's another bug filed.
The fix won't be easy and will take a bit longer.

@yokolet
Copy link
Member

yokolet commented Apr 11, 2012

I rewrote and pushed new version of push parser yesterday.

This new version doesn't use PushInputStream anymore.
As I commented on the related issue#615 , I think you won't get the exception on the new version.

@yokolet
Copy link
Member

yokolet commented Jun 13, 2012

I'm going to close this issue since I don't get any exception under new push parser.

If you, @samuelkadolph, have the same issue on the latest Nokogiri, please reopen the issue.

@yokolet yokolet closed this as completed Jun 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants