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

TypeError: object null is not iterable #501

Closed
manunio opened this issue Nov 2, 2023 · 2 comments
Closed

TypeError: object null is not iterable #501

manunio opened this issue Nov 2, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@manunio
Copy link
Contributor

manunio commented Nov 2, 2023

Describe the bug
While Fuzzing parseDocument threw uncaught exception at

const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/) as string[]

To Reproduce

> const yaml = await import("yaml")
undefined
> const data = '!!�������p: >�: >\n|\x18\x00\x00pro��)�������������������: !!\r: !!: >\n\x07\x04\x00ke'
undefined
> const docs = yaml.parseDocument(data)
Uncaught:
TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))
    at Directives.tagName (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/doc/directives.js:121:36)
    at Object.composeScalar (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/compose-scalar.js:13:26)
    at composeNode (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/compose-node.js:24:34)
    at Object.resolveBlockMap (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/resolve-block-map.js:56:15)
    at resolveCollection (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/compose-collection.js:13:27)
    at Object.composeCollection (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/compose-collection.js:47:16)
    at Object.composeNode (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/compose-node.js:31:38)
    at Object.composeDoc (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/compose-doc.js:33:23)
    at Composer.next (/home/maxx/dev/security/oss-fuzz-projects/yaml/dist/compose/composer.js:149:40)
    at next (<anonymous>)

Expected behaviour
parseDocument to not throw exception.

Versions (please complete the following information):

  • Environment: Node.js v18.18.2
  • yaml: v2.3.3

Additional context
Possible fix for this will be a check against null

diff --git a/src/doc/directives.ts b/src/doc/directives.ts
index add18fc..896c584 100644
--- a/src/doc/directives.ts
+++ b/src/doc/directives.ts
@@ -143,7 +143,12 @@ export class Directives {
       return verbatim
     }

-    const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/) as string[]
+    const matched = source.match(/^(.*!)([^!]*)$/) as string[]
+    if (!matched) {
+      onError(`The ${source} tag is invalid`)
+      return null
+    }
+    const [, handle, suffix] = matched
     if (!suffix) onError(`The ${source} tag has no suffix`)
     const prefix = this.tags[handle]
     if (prefix) {

but i was not able to reproduce this with single error message in doc.errors,

@manunio manunio added the bug Something isn't working label Nov 2, 2023
@eemeli
Copy link
Owner

eemeli commented Nov 3, 2023

Ah, that was interesting. Managed to first shorten the input that's required to replicate the issue to just ': | !\r!', and then found the right fix: adding the s dot-all flag to the regexp on the line that's throwing the error, so that its . matches the \r.

@eemeli
Copy link
Owner

eemeli commented Nov 3, 2023

Fix released as 2.3.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants