GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TypeError: object null is not iterable · Issue #501 · eemeli/yaml

TypeError: object null is not iterable #501

New issue
Copy link
New issue
Copy link
Closed
Closed
TypeError: object null is not iterable#501
Copy link
Labels
bugSomething isn't working

Description

@manunio
manunio
opened on Nov 2, 2023
Issue body actions

Describe the bug
While Fuzzing parseDocument threw uncaught exception at

yaml/src/doc/directives.ts

Line 146 in e8576e8

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,

Activity

  1. manunio
    added
    bugSomething isn't working
    on Nov 2, 2023
  2. eemeli
    added a commit that references this issue on Nov 3, 2023

    fix: Carriage return in tag shorthand (#501)

    4af7419
  3. eemeli commented on Nov 3, 2023

    @eemeli
    eemeli
    on Nov 3, 2023
    Owner
    More actions

    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.

    Reacted by manunio
  4. eemeli commented on Nov 3, 2023

    @eemeli
    eemeli
    on Nov 3, 2023
    Owner
    More actions

    Fix released as 2.3.4.

    Reacted by manunio
  5. eemeli
    closed this as completedon Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.